Skip to content

Commit 988d40a

Browse files
James-A-ClarkSuzuki K Poulose
authored andcommitted
coresight: Make trace ID map spinlock local to the map
Reduce contention on the lock by replacing the global lock with one for each map. Signed-off-by: James Clark <[email protected]> Reviewed-by: Mike Leach <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 487eec8 commit 988d40a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
11641164

11651165
if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
11661166
csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
1167+
spin_lock_init(&csdev->perf_sink_id_map.lock);
11671168
csdev->perf_sink_id_map.cpu_map = alloc_percpu(atomic_t);
11681169
if (!csdev->perf_sink_id_map.cpu_map) {
11691170
kfree(csdev);

drivers/hwtracing/coresight/coresight-trace-id.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
/* Default trace ID map. Used in sysfs mode and for system sources */
1616
static DEFINE_PER_CPU(atomic_t, id_map_default_cpu_ids) = ATOMIC_INIT(0);
1717
static struct coresight_trace_id_map id_map_default = {
18-
.cpu_map = &id_map_default_cpu_ids
18+
.cpu_map = &id_map_default_cpu_ids,
19+
.lock = __SPIN_LOCK_UNLOCKED(id_map_default.lock)
1920
};
2021

21-
/* lock to protect id_map and cpu data */
22-
static DEFINE_SPINLOCK(id_map_lock);
23-
2422
/* #define TRACE_ID_DEBUG 1 */
2523
#if defined(TRACE_ID_DEBUG) || defined(CONFIG_COMPILE_TEST)
2624

@@ -123,11 +121,11 @@ static void coresight_trace_id_release_all(struct coresight_trace_id_map *id_map
123121
unsigned long flags;
124122
int cpu;
125123

126-
spin_lock_irqsave(&id_map_lock, flags);
124+
spin_lock_irqsave(&id_map->lock, flags);
127125
bitmap_zero(id_map->used_ids, CORESIGHT_TRACE_IDS_MAX);
128126
for_each_possible_cpu(cpu)
129127
atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0);
130-
spin_unlock_irqrestore(&id_map_lock, flags);
128+
spin_unlock_irqrestore(&id_map->lock, flags);
131129
DUMP_ID_MAP(id_map);
132130
}
133131

@@ -136,7 +134,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map
136134
unsigned long flags;
137135
int id;
138136

139-
spin_lock_irqsave(&id_map_lock, flags);
137+
spin_lock_irqsave(&id_map->lock, flags);
140138

141139
/* check for existing allocation for this CPU */
142140
id = _coresight_trace_id_read_cpu_id(cpu, id_map);
@@ -163,7 +161,7 @@ static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map
163161
atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id);
164162

165163
get_cpu_id_out_unlock:
166-
spin_unlock_irqrestore(&id_map_lock, flags);
164+
spin_unlock_irqrestore(&id_map->lock, flags);
167165

168166
DUMP_ID_CPU(cpu, id);
169167
DUMP_ID_MAP(id_map);
@@ -180,12 +178,12 @@ static void _coresight_trace_id_put_cpu_id(int cpu, struct coresight_trace_id_ma
180178
if (!id)
181179
return;
182180

183-
spin_lock_irqsave(&id_map_lock, flags);
181+
spin_lock_irqsave(&id_map->lock, flags);
184182

185183
coresight_trace_id_free(id, id_map);
186184
atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0);
187185

188-
spin_unlock_irqrestore(&id_map_lock, flags);
186+
spin_unlock_irqrestore(&id_map->lock, flags);
189187
DUMP_ID_CPU(cpu, id);
190188
DUMP_ID_MAP(id_map);
191189
}
@@ -195,10 +193,10 @@ static int coresight_trace_id_map_get_system_id(struct coresight_trace_id_map *i
195193
unsigned long flags;
196194
int id;
197195

198-
spin_lock_irqsave(&id_map_lock, flags);
196+
spin_lock_irqsave(&id_map->lock, flags);
199197
/* prefer odd IDs for system components to avoid legacy CPU IDS */
200198
id = coresight_trace_id_alloc_new_id(id_map, 0, true);
201-
spin_unlock_irqrestore(&id_map_lock, flags);
199+
spin_unlock_irqrestore(&id_map->lock, flags);
202200

203201
DUMP_ID(id);
204202
DUMP_ID_MAP(id_map);
@@ -209,9 +207,9 @@ static void coresight_trace_id_map_put_system_id(struct coresight_trace_id_map *
209207
{
210208
unsigned long flags;
211209

212-
spin_lock_irqsave(&id_map_lock, flags);
210+
spin_lock_irqsave(&id_map->lock, flags);
213211
coresight_trace_id_free(id, id_map);
214-
spin_unlock_irqrestore(&id_map_lock, flags);
212+
spin_unlock_irqrestore(&id_map->lock, flags);
215213

216214
DUMP_ID(id);
217215
DUMP_ID_MAP(id_map);

include/linux/coresight.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ struct coresight_trace_id_map {
233233
DECLARE_BITMAP(used_ids, CORESIGHT_TRACE_IDS_MAX);
234234
atomic_t __percpu *cpu_map;
235235
atomic_t perf_cs_etm_session_active;
236+
spinlock_t lock;
236237
};
237238

238239
/**

0 commit comments

Comments
 (0)