Lines Matching refs:perfmon
18 void vc4_perfmon_get(struct vc4_perfmon *perfmon) in vc4_perfmon_get() argument
22 if (!perfmon) in vc4_perfmon_get()
25 vc4 = perfmon->dev; in vc4_perfmon_get()
29 refcount_inc(&perfmon->refcnt); in vc4_perfmon_get()
32 void vc4_perfmon_put(struct vc4_perfmon *perfmon) in vc4_perfmon_put() argument
36 if (!perfmon) in vc4_perfmon_put()
39 vc4 = perfmon->dev; in vc4_perfmon_put()
43 if (refcount_dec_and_test(&perfmon->refcnt)) in vc4_perfmon_put()
44 kfree(perfmon); in vc4_perfmon_put()
47 void vc4_perfmon_start(struct vc4_dev *vc4, struct vc4_perfmon *perfmon) in vc4_perfmon_start() argument
55 if (WARN_ON_ONCE(!perfmon || vc4->active_perfmon)) in vc4_perfmon_start()
58 for (i = 0; i < perfmon->ncounters; i++) in vc4_perfmon_start()
59 V3D_WRITE(V3D_PCTRS(i), perfmon->events[i]); in vc4_perfmon_start()
61 mask = GENMASK(perfmon->ncounters - 1, 0); in vc4_perfmon_start()
64 vc4->active_perfmon = perfmon; in vc4_perfmon_start()
67 void vc4_perfmon_stop(struct vc4_dev *vc4, struct vc4_perfmon *perfmon, in vc4_perfmon_stop() argument
76 perfmon != vc4->active_perfmon)) in vc4_perfmon_stop()
80 for (i = 0; i < perfmon->ncounters; i++) in vc4_perfmon_stop()
81 perfmon->counters[i] += V3D_READ(V3D_PCTR(i)); in vc4_perfmon_stop()
91 struct vc4_perfmon *perfmon; in vc4_perfmon_find() local
96 mutex_lock(&vc4file->perfmon.lock); in vc4_perfmon_find()
97 perfmon = idr_find(&vc4file->perfmon.idr, id); in vc4_perfmon_find()
98 vc4_perfmon_get(perfmon); in vc4_perfmon_find()
99 mutex_unlock(&vc4file->perfmon.lock); in vc4_perfmon_find()
101 return perfmon; in vc4_perfmon_find()
111 mutex_init(&vc4file->perfmon.lock); in vc4_perfmon_open_file()
112 idr_init_base(&vc4file->perfmon.idr, VC4_PERFMONID_MIN); in vc4_perfmon_open_file()
118 struct vc4_perfmon *perfmon = elem; in vc4_perfmon_idr_del() local
122 if (perfmon == vc4->active_perfmon) in vc4_perfmon_idr_del()
123 vc4_perfmon_stop(vc4, perfmon, false); in vc4_perfmon_idr_del()
125 vc4_perfmon_put(perfmon); in vc4_perfmon_idr_del()
137 mutex_lock(&vc4file->perfmon.lock); in vc4_perfmon_close_file()
138 idr_for_each(&vc4file->perfmon.idr, vc4_perfmon_idr_del, vc4); in vc4_perfmon_close_file()
139 idr_destroy(&vc4file->perfmon.idr); in vc4_perfmon_close_file()
140 mutex_unlock(&vc4file->perfmon.lock); in vc4_perfmon_close_file()
141 mutex_destroy(&vc4file->perfmon.lock); in vc4_perfmon_close_file()
150 struct vc4_perfmon *perfmon; in vc4_perfmon_create_ioctl() local
173 perfmon = kzalloc(struct_size(perfmon, counters, req->ncounters), in vc4_perfmon_create_ioctl()
175 if (!perfmon) in vc4_perfmon_create_ioctl()
177 perfmon->dev = vc4; in vc4_perfmon_create_ioctl()
180 perfmon->events[i] = req->events[i]; in vc4_perfmon_create_ioctl()
182 perfmon->ncounters = req->ncounters; in vc4_perfmon_create_ioctl()
184 refcount_set(&perfmon->refcnt, 1); in vc4_perfmon_create_ioctl()
186 mutex_lock(&vc4file->perfmon.lock); in vc4_perfmon_create_ioctl()
187 ret = idr_alloc(&vc4file->perfmon.idr, perfmon, VC4_PERFMONID_MIN, in vc4_perfmon_create_ioctl()
189 mutex_unlock(&vc4file->perfmon.lock); in vc4_perfmon_create_ioctl()
192 kfree(perfmon); in vc4_perfmon_create_ioctl()
206 struct vc4_perfmon *perfmon; in vc4_perfmon_destroy_ioctl() local
216 mutex_lock(&vc4file->perfmon.lock); in vc4_perfmon_destroy_ioctl()
217 perfmon = idr_remove(&vc4file->perfmon.idr, req->id); in vc4_perfmon_destroy_ioctl()
218 mutex_unlock(&vc4file->perfmon.lock); in vc4_perfmon_destroy_ioctl()
220 if (!perfmon) in vc4_perfmon_destroy_ioctl()
223 vc4_perfmon_put(perfmon); in vc4_perfmon_destroy_ioctl()
233 struct vc4_perfmon *perfmon; in vc4_perfmon_get_values_ioctl() local
244 mutex_lock(&vc4file->perfmon.lock); in vc4_perfmon_get_values_ioctl()
245 perfmon = idr_find(&vc4file->perfmon.idr, req->id); in vc4_perfmon_get_values_ioctl()
246 vc4_perfmon_get(perfmon); in vc4_perfmon_get_values_ioctl()
247 mutex_unlock(&vc4file->perfmon.lock); in vc4_perfmon_get_values_ioctl()
249 if (!perfmon) in vc4_perfmon_get_values_ioctl()
252 if (copy_to_user(u64_to_user_ptr(req->values_ptr), perfmon->counters, in vc4_perfmon_get_values_ioctl()
253 perfmon->ncounters * sizeof(u64))) in vc4_perfmon_get_values_ioctl()
258 vc4_perfmon_put(perfmon); in vc4_perfmon_get_values_ioctl()