On Wed, 2 Jul 2025 13:26:05 -0400 Steven Rostedt <rostedt@xxxxxxxxxxx> wrote: > So I'm fine with making this a 32 bit counter using 16 bits for the CPU > and 16 bits for per thread uniqueness. To still be able to use a 32 bit cmpxchg (for racing with an NMI), we could break this number up into two 32 bit words. One with the CPU that it was created on, and one with the per_cpu counter: union unwind_task_id { struct { u32 cpu; u32 cnt; } u64 id; }; static DEFINE_PER_CPU(u32, unwind_ctx_ctr); static u64 get_cookie(struct unwind_task_info *info) { u32 cpu_cnt; u32 cnt; u32 old = 0; if (info->id.cpu) return info->id.id; cpu_cnt = __this_cpu_read(unwind_ctx_ctr); cpu_cnt += 2; cnt = cpu_cnt | 1; /* Always make non zero */ if (try_cmpxchg(&info->id.cnt, &old, cnt)) { /* Update the per cpu counter */ __this_cpu_write(unwind_ctx_ctr, cpu_cnt); } /* Interrupts are disabled, the CPU will always be same */ info->id.cpu = smp_processor_id() + 1; /* Must be non zero */ return info->id.id; } When leaving the kernel it does: info->id.id = 0; -- Steve