drivers/hwtracing/coresight/coresight-trace-id.c
Source file repositories/reference/linux-study-clean/drivers/hwtracing/coresight/coresight-trace-id.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hwtracing/coresight/coresight-trace-id.c- Extension
.c- Size
- 8744 bytes
- Lines
- 301
- Domain
- Driver Families
- Bucket
- drivers/hwtracing
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/coresight.hlinux/coresight-pmu.hlinux/cpumask.hlinux/kernel.hlinux/spinlock.hlinux/types.hcoresight-trace-id.h
Detected Declarations
enum trace_id_flagsfunction coresight_trace_id_dump_tablefunction _coresight_trace_id_read_cpu_idfunction coresight_trace_id_find_odd_idfunction coresight_trace_id_alloc_new_idfunction coresight_trace_id_freefunction coresight_trace_id_release_allfunction _coresight_trace_id_get_cpu_idfunction _coresight_trace_id_put_cpu_idfunction coresight_trace_id_map_get_system_idfunction coresight_trace_id_map_put_system_idfunction coresight_trace_id_get_cpu_idfunction coresight_trace_id_get_cpu_id_mapfunction coresight_trace_id_put_cpu_idfunction coresight_trace_id_put_cpu_id_mapfunction coresight_trace_id_read_cpu_idfunction coresight_trace_id_read_cpu_id_mapfunction coresight_trace_id_get_system_idfunction coresight_trace_id_get_static_system_idfunction coresight_trace_id_put_system_idfunction coresight_trace_id_perf_startfunction coresight_trace_id_perf_stopexport coresight_trace_id_get_cpu_idexport coresight_trace_id_get_cpu_id_mapexport coresight_trace_id_put_cpu_idexport coresight_trace_id_put_cpu_id_mapexport coresight_trace_id_read_cpu_idexport coresight_trace_id_read_cpu_id_mapexport coresight_trace_id_get_system_idexport coresight_trace_id_get_static_system_idexport coresight_trace_id_put_system_idexport coresight_trace_id_perf_startexport coresight_trace_id_perf_stop
Annotated Snippet
if (!test_bit(preferred_id, id_map->used_ids)) {
id = preferred_id;
goto trace_id_allocated;
} else if (flags & TRACE_ID_REQ_STATIC)
return -EBUSY;
} else if (flags & TRACE_ID_PREFER_ODD) {
/* may use odd ids to avoid preferred legacy cpu IDs */
id = coresight_trace_id_find_odd_id(id_map);
if (id)
goto trace_id_allocated;
} else if (!IS_VALID_CS_TRACE_ID(preferred_id) &&
(flags & TRACE_ID_REQ_STATIC))
return -EINVAL;
/*
* skip reserved bit 0, look at bitmap length of
* CORESIGHT_TRACE_ID_RES_TOP from offset of bit 1.
*/
id = find_next_zero_bit(id_map->used_ids, CORESIGHT_TRACE_ID_RES_TOP, 1);
if (id >= CORESIGHT_TRACE_ID_RES_TOP)
return -EINVAL;
/* mark as used */
trace_id_allocated:
set_bit(id, id_map->used_ids);
return id;
}
static void coresight_trace_id_free(int id, struct coresight_trace_id_map *id_map)
{
if (WARN(!IS_VALID_CS_TRACE_ID(id), "Invalid Trace ID %d\n", id))
return;
if (WARN(!test_bit(id, id_map->used_ids), "Freeing unused ID %d\n", id))
return;
clear_bit(id, id_map->used_ids);
}
/*
* Release all IDs and clear CPU associations.
*/
static void coresight_trace_id_release_all(struct coresight_trace_id_map *id_map)
{
unsigned long flags;
int cpu;
raw_spin_lock_irqsave(&id_map->lock, flags);
bitmap_zero(id_map->used_ids, CORESIGHT_TRACE_IDS_MAX);
for_each_possible_cpu(cpu)
atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), 0);
raw_spin_unlock_irqrestore(&id_map->lock, flags);
DUMP_ID_MAP(id_map);
}
static int _coresight_trace_id_get_cpu_id(int cpu, struct coresight_trace_id_map *id_map)
{
unsigned long flags;
int id;
raw_spin_lock_irqsave(&id_map->lock, flags);
/* check for existing allocation for this CPU */
id = _coresight_trace_id_read_cpu_id(cpu, id_map);
if (id)
goto get_cpu_id_out_unlock;
/*
* Find a new ID.
*
* Use legacy values where possible in the dynamic trace ID allocator to
* allow older tools to continue working if they are not upgraded at the
* same time as the kernel drivers.
*
* If the generated legacy ID is invalid, or not available then the next
* available dynamic ID will be used.
*/
id = coresight_trace_id_alloc_new_id(id_map,
CORESIGHT_LEGACY_CPU_TRACE_ID(cpu),
TRACE_ID_ANY);
if (!IS_VALID_CS_TRACE_ID(id))
goto get_cpu_id_out_unlock;
/* allocate the new id to the cpu */
atomic_set(per_cpu_ptr(id_map->cpu_map, cpu), id);
get_cpu_id_out_unlock:
raw_spin_unlock_irqrestore(&id_map->lock, flags);
DUMP_ID_CPU(cpu, id);
DUMP_ID_MAP(id_map);
return id;
Annotation
- Immediate include surface: `linux/coresight.h`, `linux/coresight-pmu.h`, `linux/cpumask.h`, `linux/kernel.h`, `linux/spinlock.h`, `linux/types.h`, `coresight-trace-id.h`.
- Detected declarations: `enum trace_id_flags`, `function coresight_trace_id_dump_table`, `function _coresight_trace_id_read_cpu_id`, `function coresight_trace_id_find_odd_id`, `function coresight_trace_id_alloc_new_id`, `function coresight_trace_id_free`, `function coresight_trace_id_release_all`, `function _coresight_trace_id_get_cpu_id`, `function _coresight_trace_id_put_cpu_id`, `function coresight_trace_id_map_get_system_id`.
- Atlas domain: Driver Families / drivers/hwtracing.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.