kernel: add support for getting percpu variables that belong to other CPUs
This commit is contained in:
23
kernel/cpu.c
23
kernel/cpu.c
@@ -12,11 +12,34 @@ struct cpu_data *get_this_cpu(void)
|
||||
return percpu_get(&cpu_data);
|
||||
}
|
||||
|
||||
struct cpu_data *get_cpu(unsigned int id)
|
||||
{
|
||||
return percpu_get_from(id, &cpu_data);
|
||||
}
|
||||
|
||||
void put_cpu(struct cpu_data *cpu)
|
||||
{
|
||||
percpu_put(cpu);
|
||||
}
|
||||
|
||||
bool cpu_is_available(unsigned int cpu_id)
|
||||
{
|
||||
if (cpu_id >= CPU_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return bitmap_check(cpu_available, cpu_id);
|
||||
}
|
||||
|
||||
bool cpu_is_online(unsigned int cpu_id)
|
||||
{
|
||||
if (cpu_id >= CPU_MAX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return bitmap_check(cpu_online, cpu_id);
|
||||
}
|
||||
|
||||
void cpu_set_available(unsigned int cpu_id)
|
||||
{
|
||||
if (cpu_id >= CPU_MAX) {
|
||||
|
||||
@@ -24,7 +24,7 @@ extern kern_status_t init_per_cpu_areas(void)
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
extern void *__percpu_get(void *var)
|
||||
extern void *__percpu_get(unsigned int cpu, void *var)
|
||||
{
|
||||
uintptr_t pvar = (uintptr_t)var;
|
||||
uintptr_t percpu_start = (uintptr_t)__percpu_start;
|
||||
@@ -36,5 +36,5 @@ extern void *__percpu_get(void *var)
|
||||
|
||||
size_t var_offset = pvar - percpu_start;
|
||||
|
||||
return (char *)percpu_buffer + (this_cpu() * percpu_stride) + var_offset;
|
||||
return (char *)percpu_buffer + (cpu * percpu_stride) + var_offset;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user