Skip to content

Commit

Permalink
init: move setup of nr_cpu_ids to as early as possible
Browse files Browse the repository at this point in the history
Move the setting of nr_cpu_ids from sched_init() to start_kernel()
so that it's available as early as possible.

Note that an arch has the option of setting it even earlier if need be,
but it should not result in a different value than the setup_nr_cpu_ids()
function.

Signed-off-by: Mike Travis <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
Mike Travis authored and Ingo Molnar committed Apr 19, 2008
1 parent 4bdbaad commit e0982e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 17 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ static void __init smp_init(void)
#endif

static inline void setup_per_cpu_areas(void) { }
static inline void setup_nr_cpu_ids(void) { }
static inline void smp_prepare_cpus(unsigned int maxcpus) { }

#else
Expand All @@ -368,6 +369,21 @@ cpumask_t cpu_mask_all __read_mostly = CPU_MASK_ALL;
EXPORT_SYMBOL(cpu_mask_all);
#endif

/* Setup number of possible processor ids */
int nr_cpu_ids __read_mostly = NR_CPUS;
EXPORT_SYMBOL(nr_cpu_ids);

/* An arch may set nr_cpu_ids earlier if needed, so this would be redundant */
static void __init setup_nr_cpu_ids(void)
{
int cpu, highest_cpu = 0;

for_each_possible_cpu(cpu)
highest_cpu = cpu;

nr_cpu_ids = highest_cpu + 1;
}

#ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;

Expand Down Expand Up @@ -542,6 +558,7 @@ asmlinkage void __init start_kernel(void)
setup_command_line(command_line);
unwind_setup();
setup_per_cpu_areas();
setup_nr_cpu_ids();
smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */

/*
Expand Down
7 changes: 0 additions & 7 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -6116,10 +6116,6 @@ void __init migration_init(void)

#ifdef CONFIG_SMP

/* Number of possible processor ids */
int nr_cpu_ids __read_mostly = NR_CPUS;
EXPORT_SYMBOL(nr_cpu_ids);

#ifdef CONFIG_SCHED_DEBUG

static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
Expand Down Expand Up @@ -7478,7 +7474,6 @@ static void init_tg_rt_entry(struct rq *rq, struct task_group *tg,

void __init sched_init(void)
{
int highest_cpu = 0;
int i, j;
unsigned long alloc_size = 0, ptr;

Expand Down Expand Up @@ -7569,7 +7564,6 @@ void __init sched_init(void)
#endif
init_rq_hrtick(rq);
atomic_set(&rq->nr_iowait, 0);
highest_cpu = i;
}

set_load_weight(&init_task);
Expand All @@ -7579,7 +7573,6 @@ void __init sched_init(void)
#endif

#ifdef CONFIG_SMP
nr_cpu_ids = highest_cpu + 1;
open_softirq(SCHED_SOFTIRQ, run_rebalance_domains, NULL);
#endif

Expand Down

0 comments on commit e0982e9

Please sign in to comment.