Skip to content

Commit

Permalink
cpu: Add iterators for "present" CPUs
Browse files Browse the repository at this point in the history
Some code path want to look at all the CPUs that are "present",
which means they have been enabled by HB/Cronus and can be accessed
via XSCOMs, even if they haven't called in yet.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
ozbenh authored and stewartsmith committed Jan 5, 2017
1 parent ee5c9e9 commit c38fdc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/cpu.c
Expand Up @@ -494,6 +494,20 @@ struct cpu_thread *first_available_cpu(void)
return next_available_cpu(NULL);
}

struct cpu_thread *next_present_cpu(struct cpu_thread *cpu)
{
do {
cpu = next_cpu(cpu);
} while(cpu && !cpu_is_present(cpu));

return cpu;
}

struct cpu_thread *first_present_cpu(void)
{
return next_present_cpu(NULL);
}

u8 get_available_nr_cores_in_chip(u32 chip_id)
{
struct cpu_thread *core;
Expand Down
10 changes: 10 additions & 0 deletions include/cpu.h
Expand Up @@ -165,6 +165,11 @@ extern struct cpu_thread *next_cpu(struct cpu_thread *cpu);
* this API standpoint.
*/

static inline bool cpu_is_present(struct cpu_thread *cpu)
{
return cpu->state >= cpu_state_present;
}

static inline bool cpu_is_available(struct cpu_thread *cpu)
{
return cpu->state == cpu_state_active ||
Expand All @@ -173,13 +178,18 @@ static inline bool cpu_is_available(struct cpu_thread *cpu)

extern struct cpu_thread *first_available_cpu(void);
extern struct cpu_thread *next_available_cpu(struct cpu_thread *cpu);
extern struct cpu_thread *first_present_cpu(void);
extern struct cpu_thread *next_present_cpu(struct cpu_thread *cpu);

#define for_each_cpu(cpu) \
for (cpu = first_cpu(); cpu; cpu = next_cpu(cpu))

#define for_each_available_cpu(cpu) \
for (cpu = first_available_cpu(); cpu; cpu = next_available_cpu(cpu))

#define for_each_present_cpu(cpu) \
for (cpu = first_present_cpu(); cpu; cpu = next_present_cpu(cpu))

extern struct cpu_thread *first_available_core_in_chip(u32 chip_id);
extern struct cpu_thread *next_available_core_in_chip(struct cpu_thread *cpu, u32 chip_id);
extern u8 get_available_nr_cores_in_chip(u32 chip_id);
Expand Down

0 comments on commit c38fdc4

Please sign in to comment.