smp.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /* smp.c: Sparc64 SMP support.
  2. *
  3. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  4. */
  5. #include <linux/module.h>
  6. #include <linux/kernel.h>
  7. #include <linux/sched.h>
  8. #include <linux/mm.h>
  9. #include <linux/pagemap.h>
  10. #include <linux/threads.h>
  11. #include <linux/smp.h>
  12. #include <linux/smp_lock.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/cache.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/profile.h>
  23. #include <linux/bootmem.h>
  24. #include <asm/head.h>
  25. #include <asm/ptrace.h>
  26. #include <asm/atomic.h>
  27. #include <asm/tlbflush.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/cpudata.h>
  30. #include <asm/irq.h>
  31. #include <asm/page.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/oplib.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/timer.h>
  36. #include <asm/starfire.h>
  37. #include <asm/tlb.h>
  38. #include <asm/sections.h>
  39. extern void calibrate_delay(void);
  40. /* Please don't make this stuff initdata!!! --DaveM */
  41. static unsigned char boot_cpu_id;
  42. cpumask_t cpu_online_map __read_mostly = CPU_MASK_NONE;
  43. cpumask_t phys_cpu_present_map __read_mostly = CPU_MASK_NONE;
  44. static cpumask_t smp_commenced_mask;
  45. static cpumask_t cpu_callout_map;
  46. void smp_info(struct seq_file *m)
  47. {
  48. int i;
  49. seq_printf(m, "State:\n");
  50. for (i = 0; i < NR_CPUS; i++) {
  51. if (cpu_online(i))
  52. seq_printf(m,
  53. "CPU%d:\t\tonline\n", i);
  54. }
  55. }
  56. void smp_bogo(struct seq_file *m)
  57. {
  58. int i;
  59. for (i = 0; i < NR_CPUS; i++)
  60. if (cpu_online(i))
  61. seq_printf(m,
  62. "Cpu%dBogo\t: %lu.%02lu\n"
  63. "Cpu%dClkTck\t: %016lx\n",
  64. i, cpu_data(i).udelay_val / (500000/HZ),
  65. (cpu_data(i).udelay_val / (5000/HZ)) % 100,
  66. i, cpu_data(i).clock_tick);
  67. }
  68. void __init smp_store_cpu_info(int id)
  69. {
  70. int cpu_node;
  71. /* multiplier and counter set by
  72. smp_setup_percpu_timer() */
  73. cpu_data(id).udelay_val = loops_per_jiffy;
  74. cpu_find_by_mid(id, &cpu_node);
  75. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  76. "clock-frequency", 0);
  77. cpu_data(id).idle_volume = 1;
  78. cpu_data(id).dcache_size = prom_getintdefault(cpu_node, "dcache-size",
  79. 16 * 1024);
  80. cpu_data(id).dcache_line_size =
  81. prom_getintdefault(cpu_node, "dcache-line-size", 32);
  82. cpu_data(id).icache_size = prom_getintdefault(cpu_node, "icache-size",
  83. 16 * 1024);
  84. cpu_data(id).icache_line_size =
  85. prom_getintdefault(cpu_node, "icache-line-size", 32);
  86. cpu_data(id).ecache_size = prom_getintdefault(cpu_node, "ecache-size",
  87. 4 * 1024 * 1024);
  88. cpu_data(id).ecache_line_size =
  89. prom_getintdefault(cpu_node, "ecache-line-size", 64);
  90. printk("CPU[%d]: Caches "
  91. "D[sz(%d):line_sz(%d)] "
  92. "I[sz(%d):line_sz(%d)] "
  93. "E[sz(%d):line_sz(%d)]\n",
  94. id,
  95. cpu_data(id).dcache_size, cpu_data(id).dcache_line_size,
  96. cpu_data(id).icache_size, cpu_data(id).icache_line_size,
  97. cpu_data(id).ecache_size, cpu_data(id).ecache_line_size);
  98. }
  99. static void smp_setup_percpu_timer(void);
  100. static volatile unsigned long callin_flag = 0;
  101. void __init smp_callin(void)
  102. {
  103. int cpuid = hard_smp_processor_id();
  104. __local_per_cpu_offset = __per_cpu_offset(cpuid);
  105. if (tlb_type == hypervisor) {
  106. sun4v_register_fault_status();
  107. sun4v_ktsb_register();
  108. }
  109. __flush_tlb_all();
  110. smp_setup_percpu_timer();
  111. if (cheetah_pcache_forced_on)
  112. cheetah_enable_pcache();
  113. local_irq_enable();
  114. calibrate_delay();
  115. smp_store_cpu_info(cpuid);
  116. callin_flag = 1;
  117. __asm__ __volatile__("membar #Sync\n\t"
  118. "flush %%g6" : : : "memory");
  119. /* Clear this or we will die instantly when we
  120. * schedule back to this idler...
  121. */
  122. current_thread_info()->new_child = 0;
  123. /* Attach to the address space of init_task. */
  124. atomic_inc(&init_mm.mm_count);
  125. current->active_mm = &init_mm;
  126. while (!cpu_isset(cpuid, smp_commenced_mask))
  127. rmb();
  128. cpu_set(cpuid, cpu_online_map);
  129. /* idle thread is expected to have preempt disabled */
  130. preempt_disable();
  131. }
  132. void cpu_panic(void)
  133. {
  134. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  135. panic("SMP bolixed\n");
  136. }
  137. static unsigned long current_tick_offset __read_mostly;
  138. /* This tick register synchronization scheme is taken entirely from
  139. * the ia64 port, see arch/ia64/kernel/smpboot.c for details and credit.
  140. *
  141. * The only change I've made is to rework it so that the master
  142. * initiates the synchonization instead of the slave. -DaveM
  143. */
  144. #define MASTER 0
  145. #define SLAVE (SMP_CACHE_BYTES/sizeof(unsigned long))
  146. #define NUM_ROUNDS 64 /* magic value */
  147. #define NUM_ITERS 5 /* likewise */
  148. static DEFINE_SPINLOCK(itc_sync_lock);
  149. static unsigned long go[SLAVE + 1];
  150. #define DEBUG_TICK_SYNC 0
  151. static inline long get_delta (long *rt, long *master)
  152. {
  153. unsigned long best_t0 = 0, best_t1 = ~0UL, best_tm = 0;
  154. unsigned long tcenter, t0, t1, tm;
  155. unsigned long i;
  156. for (i = 0; i < NUM_ITERS; i++) {
  157. t0 = tick_ops->get_tick();
  158. go[MASTER] = 1;
  159. membar_storeload();
  160. while (!(tm = go[SLAVE]))
  161. rmb();
  162. go[SLAVE] = 0;
  163. wmb();
  164. t1 = tick_ops->get_tick();
  165. if (t1 - t0 < best_t1 - best_t0)
  166. best_t0 = t0, best_t1 = t1, best_tm = tm;
  167. }
  168. *rt = best_t1 - best_t0;
  169. *master = best_tm - best_t0;
  170. /* average best_t0 and best_t1 without overflow: */
  171. tcenter = (best_t0/2 + best_t1/2);
  172. if (best_t0 % 2 + best_t1 % 2 == 2)
  173. tcenter++;
  174. return tcenter - best_tm;
  175. }
  176. void smp_synchronize_tick_client(void)
  177. {
  178. long i, delta, adj, adjust_latency = 0, done = 0;
  179. unsigned long flags, rt, master_time_stamp, bound;
  180. #if DEBUG_TICK_SYNC
  181. struct {
  182. long rt; /* roundtrip time */
  183. long master; /* master's timestamp */
  184. long diff; /* difference between midpoint and master's timestamp */
  185. long lat; /* estimate of itc adjustment latency */
  186. } t[NUM_ROUNDS];
  187. #endif
  188. go[MASTER] = 1;
  189. while (go[MASTER])
  190. rmb();
  191. local_irq_save(flags);
  192. {
  193. for (i = 0; i < NUM_ROUNDS; i++) {
  194. delta = get_delta(&rt, &master_time_stamp);
  195. if (delta == 0) {
  196. done = 1; /* let's lock on to this... */
  197. bound = rt;
  198. }
  199. if (!done) {
  200. if (i > 0) {
  201. adjust_latency += -delta;
  202. adj = -delta + adjust_latency/4;
  203. } else
  204. adj = -delta;
  205. tick_ops->add_tick(adj, current_tick_offset);
  206. }
  207. #if DEBUG_TICK_SYNC
  208. t[i].rt = rt;
  209. t[i].master = master_time_stamp;
  210. t[i].diff = delta;
  211. t[i].lat = adjust_latency/4;
  212. #endif
  213. }
  214. }
  215. local_irq_restore(flags);
  216. #if DEBUG_TICK_SYNC
  217. for (i = 0; i < NUM_ROUNDS; i++)
  218. printk("rt=%5ld master=%5ld diff=%5ld adjlat=%5ld\n",
  219. t[i].rt, t[i].master, t[i].diff, t[i].lat);
  220. #endif
  221. printk(KERN_INFO "CPU %d: synchronized TICK with master CPU (last diff %ld cycles,"
  222. "maxerr %lu cycles)\n", smp_processor_id(), delta, rt);
  223. }
  224. static void smp_start_sync_tick_client(int cpu);
  225. static void smp_synchronize_one_tick(int cpu)
  226. {
  227. unsigned long flags, i;
  228. go[MASTER] = 0;
  229. smp_start_sync_tick_client(cpu);
  230. /* wait for client to be ready */
  231. while (!go[MASTER])
  232. rmb();
  233. /* now let the client proceed into his loop */
  234. go[MASTER] = 0;
  235. membar_storeload();
  236. spin_lock_irqsave(&itc_sync_lock, flags);
  237. {
  238. for (i = 0; i < NUM_ROUNDS*NUM_ITERS; i++) {
  239. while (!go[MASTER])
  240. rmb();
  241. go[MASTER] = 0;
  242. wmb();
  243. go[SLAVE] = tick_ops->get_tick();
  244. membar_storeload();
  245. }
  246. }
  247. spin_unlock_irqrestore(&itc_sync_lock, flags);
  248. }
  249. extern unsigned long sparc64_cpu_startup;
  250. /* The OBP cpu startup callback truncates the 3rd arg cookie to
  251. * 32-bits (I think) so to be safe we have it read the pointer
  252. * contained here so we work on >4GB machines. -DaveM
  253. */
  254. static struct thread_info *cpu_new_thread = NULL;
  255. static int __devinit smp_boot_one_cpu(unsigned int cpu)
  256. {
  257. unsigned long entry =
  258. (unsigned long)(&sparc64_cpu_startup);
  259. unsigned long cookie =
  260. (unsigned long)(&cpu_new_thread);
  261. struct task_struct *p;
  262. int timeout, ret, cpu_node;
  263. p = fork_idle(cpu);
  264. callin_flag = 0;
  265. cpu_new_thread = task_thread_info(p);
  266. cpu_set(cpu, cpu_callout_map);
  267. cpu_find_by_mid(cpu, &cpu_node);
  268. prom_startcpu(cpu_node, entry, cookie);
  269. for (timeout = 0; timeout < 5000000; timeout++) {
  270. if (callin_flag)
  271. break;
  272. udelay(100);
  273. }
  274. if (callin_flag) {
  275. ret = 0;
  276. } else {
  277. printk("Processor %d is stuck.\n", cpu);
  278. cpu_clear(cpu, cpu_callout_map);
  279. ret = -ENODEV;
  280. }
  281. cpu_new_thread = NULL;
  282. return ret;
  283. }
  284. static void spitfire_xcall_helper(u64 data0, u64 data1, u64 data2, u64 pstate, unsigned long cpu)
  285. {
  286. u64 result, target;
  287. int stuck, tmp;
  288. if (this_is_starfire) {
  289. /* map to real upaid */
  290. cpu = (((cpu & 0x3c) << 1) |
  291. ((cpu & 0x40) >> 4) |
  292. (cpu & 0x3));
  293. }
  294. target = (cpu << 14) | 0x70;
  295. again:
  296. /* Ok, this is the real Spitfire Errata #54.
  297. * One must read back from a UDB internal register
  298. * after writes to the UDB interrupt dispatch, but
  299. * before the membar Sync for that write.
  300. * So we use the high UDB control register (ASI 0x7f,
  301. * ADDR 0x20) for the dummy read. -DaveM
  302. */
  303. tmp = 0x40;
  304. __asm__ __volatile__(
  305. "wrpr %1, %2, %%pstate\n\t"
  306. "stxa %4, [%0] %3\n\t"
  307. "stxa %5, [%0+%8] %3\n\t"
  308. "add %0, %8, %0\n\t"
  309. "stxa %6, [%0+%8] %3\n\t"
  310. "membar #Sync\n\t"
  311. "stxa %%g0, [%7] %3\n\t"
  312. "membar #Sync\n\t"
  313. "mov 0x20, %%g1\n\t"
  314. "ldxa [%%g1] 0x7f, %%g0\n\t"
  315. "membar #Sync"
  316. : "=r" (tmp)
  317. : "r" (pstate), "i" (PSTATE_IE), "i" (ASI_INTR_W),
  318. "r" (data0), "r" (data1), "r" (data2), "r" (target),
  319. "r" (0x10), "0" (tmp)
  320. : "g1");
  321. /* NOTE: PSTATE_IE is still clear. */
  322. stuck = 100000;
  323. do {
  324. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  325. : "=r" (result)
  326. : "i" (ASI_INTR_DISPATCH_STAT));
  327. if (result == 0) {
  328. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  329. : : "r" (pstate));
  330. return;
  331. }
  332. stuck -= 1;
  333. if (stuck == 0)
  334. break;
  335. } while (result & 0x1);
  336. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  337. : : "r" (pstate));
  338. if (stuck == 0) {
  339. printk("CPU[%d]: mondo stuckage result[%016lx]\n",
  340. smp_processor_id(), result);
  341. } else {
  342. udelay(2);
  343. goto again;
  344. }
  345. }
  346. static __inline__ void spitfire_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  347. {
  348. u64 pstate;
  349. int i;
  350. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  351. for_each_cpu_mask(i, mask)
  352. spitfire_xcall_helper(data0, data1, data2, pstate, i);
  353. }
  354. /* Cheetah now allows to send the whole 64-bytes of data in the interrupt
  355. * packet, but we have no use for that. However we do take advantage of
  356. * the new pipelining feature (ie. dispatch to multiple cpus simultaneously).
  357. */
  358. static void cheetah_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  359. {
  360. u64 pstate, ver;
  361. int nack_busy_id, is_jbus;
  362. if (cpus_empty(mask))
  363. return;
  364. /* Unfortunately, someone at Sun had the brilliant idea to make the
  365. * busy/nack fields hard-coded by ITID number for this Ultra-III
  366. * derivative processor.
  367. */
  368. __asm__ ("rdpr %%ver, %0" : "=r" (ver));
  369. is_jbus = ((ver >> 32) == __JALAPENO_ID ||
  370. (ver >> 32) == __SERRANO_ID);
  371. __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
  372. retry:
  373. __asm__ __volatile__("wrpr %0, %1, %%pstate\n\t"
  374. : : "r" (pstate), "i" (PSTATE_IE));
  375. /* Setup the dispatch data registers. */
  376. __asm__ __volatile__("stxa %0, [%3] %6\n\t"
  377. "stxa %1, [%4] %6\n\t"
  378. "stxa %2, [%5] %6\n\t"
  379. "membar #Sync\n\t"
  380. : /* no outputs */
  381. : "r" (data0), "r" (data1), "r" (data2),
  382. "r" (0x40), "r" (0x50), "r" (0x60),
  383. "i" (ASI_INTR_W));
  384. nack_busy_id = 0;
  385. {
  386. int i;
  387. for_each_cpu_mask(i, mask) {
  388. u64 target = (i << 14) | 0x70;
  389. if (!is_jbus)
  390. target |= (nack_busy_id << 24);
  391. __asm__ __volatile__(
  392. "stxa %%g0, [%0] %1\n\t"
  393. "membar #Sync\n\t"
  394. : /* no outputs */
  395. : "r" (target), "i" (ASI_INTR_W));
  396. nack_busy_id++;
  397. }
  398. }
  399. /* Now, poll for completion. */
  400. {
  401. u64 dispatch_stat;
  402. long stuck;
  403. stuck = 100000 * nack_busy_id;
  404. do {
  405. __asm__ __volatile__("ldxa [%%g0] %1, %0"
  406. : "=r" (dispatch_stat)
  407. : "i" (ASI_INTR_DISPATCH_STAT));
  408. if (dispatch_stat == 0UL) {
  409. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  410. : : "r" (pstate));
  411. return;
  412. }
  413. if (!--stuck)
  414. break;
  415. } while (dispatch_stat & 0x5555555555555555UL);
  416. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  417. : : "r" (pstate));
  418. if ((dispatch_stat & ~(0x5555555555555555UL)) == 0) {
  419. /* Busy bits will not clear, continue instead
  420. * of freezing up on this cpu.
  421. */
  422. printk("CPU[%d]: mondo stuckage result[%016lx]\n",
  423. smp_processor_id(), dispatch_stat);
  424. } else {
  425. int i, this_busy_nack = 0;
  426. /* Delay some random time with interrupts enabled
  427. * to prevent deadlock.
  428. */
  429. udelay(2 * nack_busy_id);
  430. /* Clear out the mask bits for cpus which did not
  431. * NACK us.
  432. */
  433. for_each_cpu_mask(i, mask) {
  434. u64 check_mask;
  435. if (is_jbus)
  436. check_mask = (0x2UL << (2*i));
  437. else
  438. check_mask = (0x2UL <<
  439. this_busy_nack);
  440. if ((dispatch_stat & check_mask) == 0)
  441. cpu_clear(i, mask);
  442. this_busy_nack += 2;
  443. }
  444. goto retry;
  445. }
  446. }
  447. }
  448. #if 0
  449. /* Multi-cpu list version. */
  450. static int init_cpu_list(u16 *list, cpumask_t mask)
  451. {
  452. int i, cnt;
  453. cnt = 0;
  454. for_each_cpu_mask(i, mask)
  455. list[cnt++] = i;
  456. return cnt;
  457. }
  458. static int update_cpu_list(u16 *list, int orig_cnt, cpumask_t mask)
  459. {
  460. int i;
  461. for (i = 0; i < orig_cnt; i++) {
  462. if (list[i] == 0xffff)
  463. cpu_clear(i, mask);
  464. }
  465. return init_cpu_list(list, mask);
  466. }
  467. static void hypervisor_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  468. {
  469. int this_cpu = get_cpu();
  470. struct trap_per_cpu *tb = &trap_block[this_cpu];
  471. u64 *mondo = __va(tb->cpu_mondo_block_pa);
  472. u16 *cpu_list = __va(tb->cpu_list_pa);
  473. int cnt, retries;
  474. mondo[0] = data0;
  475. mondo[1] = data1;
  476. mondo[2] = data2;
  477. wmb();
  478. retries = 0;
  479. cnt = init_cpu_list(cpu_list, mask);
  480. do {
  481. register unsigned long func __asm__("%o5");
  482. register unsigned long arg0 __asm__("%o0");
  483. register unsigned long arg1 __asm__("%o1");
  484. register unsigned long arg2 __asm__("%o2");
  485. func = HV_FAST_CPU_MONDO_SEND;
  486. arg0 = cnt;
  487. arg1 = tb->cpu_list_pa;
  488. arg2 = tb->cpu_mondo_block_pa;
  489. __asm__ __volatile__("ta %8"
  490. : "=&r" (func), "=&r" (arg0),
  491. "=&r" (arg1), "=&r" (arg2)
  492. : "0" (func), "1" (arg0),
  493. "2" (arg1), "3" (arg2),
  494. "i" (HV_FAST_TRAP)
  495. : "memory");
  496. if (likely(arg0 == HV_EOK))
  497. break;
  498. if (unlikely(++retries > 100)) {
  499. printk("CPU[%d]: sun4v mondo error %lu\n",
  500. this_cpu, func);
  501. break;
  502. }
  503. cnt = update_cpu_list(cpu_list, cnt, mask);
  504. udelay(2 * cnt);
  505. } while (1);
  506. put_cpu();
  507. }
  508. #else
  509. /* Single-cpu list version. */
  510. static void hypervisor_xcall_deliver(u64 data0, u64 data1, u64 data2, cpumask_t mask)
  511. {
  512. int this_cpu = get_cpu();
  513. struct trap_per_cpu *tb = &trap_block[this_cpu];
  514. u64 *mondo = __va(tb->cpu_mondo_block_pa);
  515. u16 *cpu_list = __va(tb->cpu_list_pa);
  516. int i;
  517. mondo[0] = data0;
  518. mondo[1] = data1;
  519. mondo[2] = data2;
  520. wmb();
  521. for_each_cpu_mask(i, mask) {
  522. int retries = 0;
  523. do {
  524. register unsigned long func __asm__("%o5");
  525. register unsigned long arg0 __asm__("%o0");
  526. register unsigned long arg1 __asm__("%o1");
  527. register unsigned long arg2 __asm__("%o2");
  528. cpu_list[0] = i;
  529. func = HV_FAST_CPU_MONDO_SEND;
  530. arg0 = 1;
  531. arg1 = tb->cpu_list_pa;
  532. arg2 = tb->cpu_mondo_block_pa;
  533. __asm__ __volatile__("ta %8"
  534. : "=&r" (func), "=&r" (arg0),
  535. "=&r" (arg1), "=&r" (arg2)
  536. : "0" (func), "1" (arg0),
  537. "2" (arg1), "3" (arg2),
  538. "i" (HV_FAST_TRAP)
  539. : "memory");
  540. if (likely(arg0 == HV_EOK))
  541. break;
  542. if (unlikely(++retries > 100)) {
  543. printk("CPU[%d]: sun4v mondo error %lu\n",
  544. this_cpu, func);
  545. break;
  546. }
  547. udelay(2 * i);
  548. } while (1);
  549. }
  550. put_cpu();
  551. }
  552. #endif
  553. /* Send cross call to all processors mentioned in MASK
  554. * except self.
  555. */
  556. static void smp_cross_call_masked(unsigned long *func, u32 ctx, u64 data1, u64 data2, cpumask_t mask)
  557. {
  558. u64 data0 = (((u64)ctx)<<32 | (((u64)func) & 0xffffffff));
  559. int this_cpu = get_cpu();
  560. cpus_and(mask, mask, cpu_online_map);
  561. cpu_clear(this_cpu, mask);
  562. if (tlb_type == spitfire)
  563. spitfire_xcall_deliver(data0, data1, data2, mask);
  564. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  565. cheetah_xcall_deliver(data0, data1, data2, mask);
  566. else
  567. hypervisor_xcall_deliver(data0, data1, data2, mask);
  568. /* NOTE: Caller runs local copy on master. */
  569. put_cpu();
  570. }
  571. extern unsigned long xcall_sync_tick;
  572. static void smp_start_sync_tick_client(int cpu)
  573. {
  574. cpumask_t mask = cpumask_of_cpu(cpu);
  575. smp_cross_call_masked(&xcall_sync_tick,
  576. 0, 0, 0, mask);
  577. }
  578. /* Send cross call to all processors except self. */
  579. #define smp_cross_call(func, ctx, data1, data2) \
  580. smp_cross_call_masked(func, ctx, data1, data2, cpu_online_map)
  581. struct call_data_struct {
  582. void (*func) (void *info);
  583. void *info;
  584. atomic_t finished;
  585. int wait;
  586. };
  587. static DEFINE_SPINLOCK(call_lock);
  588. static struct call_data_struct *call_data;
  589. extern unsigned long xcall_call_function;
  590. /*
  591. * You must not call this function with disabled interrupts or from a
  592. * hardware interrupt handler or from a bottom half handler.
  593. */
  594. static int smp_call_function_mask(void (*func)(void *info), void *info,
  595. int nonatomic, int wait, cpumask_t mask)
  596. {
  597. struct call_data_struct data;
  598. int cpus = cpus_weight(mask) - 1;
  599. long timeout;
  600. if (!cpus)
  601. return 0;
  602. /* Can deadlock when called with interrupts disabled */
  603. WARN_ON(irqs_disabled());
  604. data.func = func;
  605. data.info = info;
  606. atomic_set(&data.finished, 0);
  607. data.wait = wait;
  608. spin_lock(&call_lock);
  609. call_data = &data;
  610. smp_cross_call_masked(&xcall_call_function, 0, 0, 0, mask);
  611. /*
  612. * Wait for other cpus to complete function or at
  613. * least snap the call data.
  614. */
  615. timeout = 1000000;
  616. while (atomic_read(&data.finished) != cpus) {
  617. if (--timeout <= 0)
  618. goto out_timeout;
  619. barrier();
  620. udelay(1);
  621. }
  622. spin_unlock(&call_lock);
  623. return 0;
  624. out_timeout:
  625. spin_unlock(&call_lock);
  626. printk("XCALL: Remote cpus not responding, ncpus=%ld finished=%ld\n",
  627. (long) num_online_cpus() - 1L,
  628. (long) atomic_read(&data.finished));
  629. return 0;
  630. }
  631. int smp_call_function(void (*func)(void *info), void *info,
  632. int nonatomic, int wait)
  633. {
  634. return smp_call_function_mask(func, info, nonatomic, wait,
  635. cpu_online_map);
  636. }
  637. void smp_call_function_client(int irq, struct pt_regs *regs)
  638. {
  639. void (*func) (void *info) = call_data->func;
  640. void *info = call_data->info;
  641. clear_softint(1 << irq);
  642. if (call_data->wait) {
  643. /* let initiator proceed only after completion */
  644. func(info);
  645. atomic_inc(&call_data->finished);
  646. } else {
  647. /* let initiator proceed after getting data */
  648. atomic_inc(&call_data->finished);
  649. func(info);
  650. }
  651. }
  652. static void tsb_sync(void *info)
  653. {
  654. struct mm_struct *mm = info;
  655. if (current->active_mm == mm)
  656. tsb_context_switch(mm);
  657. }
  658. void smp_tsb_sync(struct mm_struct *mm)
  659. {
  660. smp_call_function_mask(tsb_sync, mm, 0, 1, mm->cpu_vm_mask);
  661. }
  662. extern unsigned long xcall_flush_tlb_mm;
  663. extern unsigned long xcall_flush_tlb_pending;
  664. extern unsigned long xcall_flush_tlb_kernel_range;
  665. extern unsigned long xcall_report_regs;
  666. extern unsigned long xcall_receive_signal;
  667. #ifdef DCACHE_ALIASING_POSSIBLE
  668. extern unsigned long xcall_flush_dcache_page_cheetah;
  669. #endif
  670. extern unsigned long xcall_flush_dcache_page_spitfire;
  671. #ifdef CONFIG_DEBUG_DCFLUSH
  672. extern atomic_t dcpage_flushes;
  673. extern atomic_t dcpage_flushes_xcall;
  674. #endif
  675. static __inline__ void __local_flush_dcache_page(struct page *page)
  676. {
  677. #ifdef DCACHE_ALIASING_POSSIBLE
  678. __flush_dcache_page(page_address(page),
  679. ((tlb_type == spitfire) &&
  680. page_mapping(page) != NULL));
  681. #else
  682. if (page_mapping(page) != NULL &&
  683. tlb_type == spitfire)
  684. __flush_icache_page(__pa(page_address(page)));
  685. #endif
  686. }
  687. void smp_flush_dcache_page_impl(struct page *page, int cpu)
  688. {
  689. cpumask_t mask = cpumask_of_cpu(cpu);
  690. int this_cpu;
  691. if (tlb_type == hypervisor)
  692. return;
  693. #ifdef CONFIG_DEBUG_DCFLUSH
  694. atomic_inc(&dcpage_flushes);
  695. #endif
  696. this_cpu = get_cpu();
  697. if (cpu == this_cpu) {
  698. __local_flush_dcache_page(page);
  699. } else if (cpu_online(cpu)) {
  700. void *pg_addr = page_address(page);
  701. u64 data0;
  702. if (tlb_type == spitfire) {
  703. data0 =
  704. ((u64)&xcall_flush_dcache_page_spitfire);
  705. if (page_mapping(page) != NULL)
  706. data0 |= ((u64)1 << 32);
  707. spitfire_xcall_deliver(data0,
  708. __pa(pg_addr),
  709. (u64) pg_addr,
  710. mask);
  711. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  712. #ifdef DCACHE_ALIASING_POSSIBLE
  713. data0 =
  714. ((u64)&xcall_flush_dcache_page_cheetah);
  715. cheetah_xcall_deliver(data0,
  716. __pa(pg_addr),
  717. 0, mask);
  718. #endif
  719. }
  720. #ifdef CONFIG_DEBUG_DCFLUSH
  721. atomic_inc(&dcpage_flushes_xcall);
  722. #endif
  723. }
  724. put_cpu();
  725. }
  726. void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
  727. {
  728. void *pg_addr = page_address(page);
  729. cpumask_t mask = cpu_online_map;
  730. u64 data0;
  731. int this_cpu;
  732. if (tlb_type == hypervisor)
  733. return;
  734. this_cpu = get_cpu();
  735. cpu_clear(this_cpu, mask);
  736. #ifdef CONFIG_DEBUG_DCFLUSH
  737. atomic_inc(&dcpage_flushes);
  738. #endif
  739. if (cpus_empty(mask))
  740. goto flush_self;
  741. if (tlb_type == spitfire) {
  742. data0 = ((u64)&xcall_flush_dcache_page_spitfire);
  743. if (page_mapping(page) != NULL)
  744. data0 |= ((u64)1 << 32);
  745. spitfire_xcall_deliver(data0,
  746. __pa(pg_addr),
  747. (u64) pg_addr,
  748. mask);
  749. } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
  750. #ifdef DCACHE_ALIASING_POSSIBLE
  751. data0 = ((u64)&xcall_flush_dcache_page_cheetah);
  752. cheetah_xcall_deliver(data0,
  753. __pa(pg_addr),
  754. 0, mask);
  755. #endif
  756. }
  757. #ifdef CONFIG_DEBUG_DCFLUSH
  758. atomic_inc(&dcpage_flushes_xcall);
  759. #endif
  760. flush_self:
  761. __local_flush_dcache_page(page);
  762. put_cpu();
  763. }
  764. void smp_receive_signal(int cpu)
  765. {
  766. cpumask_t mask = cpumask_of_cpu(cpu);
  767. if (cpu_online(cpu)) {
  768. u64 data0 = (((u64)&xcall_receive_signal) & 0xffffffff);
  769. if (tlb_type == spitfire)
  770. spitfire_xcall_deliver(data0, 0, 0, mask);
  771. else if (tlb_type == cheetah || tlb_type == cheetah_plus)
  772. cheetah_xcall_deliver(data0, 0, 0, mask);
  773. else if (tlb_type == hypervisor)
  774. hypervisor_xcall_deliver(data0, 0, 0, mask);
  775. }
  776. }
  777. void smp_receive_signal_client(int irq, struct pt_regs *regs)
  778. {
  779. /* Just return, rtrap takes care of the rest. */
  780. clear_softint(1 << irq);
  781. }
  782. void smp_report_regs(void)
  783. {
  784. smp_cross_call(&xcall_report_regs, 0, 0, 0);
  785. }
  786. /* We know that the window frames of the user have been flushed
  787. * to the stack before we get here because all callers of us
  788. * are flush_tlb_*() routines, and these run after flush_cache_*()
  789. * which performs the flushw.
  790. *
  791. * The SMP TLB coherency scheme we use works as follows:
  792. *
  793. * 1) mm->cpu_vm_mask is a bit mask of which cpus an address
  794. * space has (potentially) executed on, this is the heuristic
  795. * we use to avoid doing cross calls.
  796. *
  797. * Also, for flushing from kswapd and also for clones, we
  798. * use cpu_vm_mask as the list of cpus to make run the TLB.
  799. *
  800. * 2) TLB context numbers are shared globally across all processors
  801. * in the system, this allows us to play several games to avoid
  802. * cross calls.
  803. *
  804. * One invariant is that when a cpu switches to a process, and
  805. * that processes tsk->active_mm->cpu_vm_mask does not have the
  806. * current cpu's bit set, that tlb context is flushed locally.
  807. *
  808. * If the address space is non-shared (ie. mm->count == 1) we avoid
  809. * cross calls when we want to flush the currently running process's
  810. * tlb state. This is done by clearing all cpu bits except the current
  811. * processor's in current->active_mm->cpu_vm_mask and performing the
  812. * flush locally only. This will force any subsequent cpus which run
  813. * this task to flush the context from the local tlb if the process
  814. * migrates to another cpu (again).
  815. *
  816. * 3) For shared address spaces (threads) and swapping we bite the
  817. * bullet for most cases and perform the cross call (but only to
  818. * the cpus listed in cpu_vm_mask).
  819. *
  820. * The performance gain from "optimizing" away the cross call for threads is
  821. * questionable (in theory the big win for threads is the massive sharing of
  822. * address space state across processors).
  823. */
  824. /* This currently is only used by the hugetlb arch pre-fault
  825. * hook on UltraSPARC-III+ and later when changing the pagesize
  826. * bits of the context register for an address space.
  827. */
  828. void smp_flush_tlb_mm(struct mm_struct *mm)
  829. {
  830. u32 ctx = CTX_HWBITS(mm->context);
  831. int cpu = get_cpu();
  832. if (atomic_read(&mm->mm_users) == 1) {
  833. mm->cpu_vm_mask = cpumask_of_cpu(cpu);
  834. goto local_flush_and_out;
  835. }
  836. smp_cross_call_masked(&xcall_flush_tlb_mm,
  837. ctx, 0, 0,
  838. mm->cpu_vm_mask);
  839. local_flush_and_out:
  840. __flush_tlb_mm(ctx, SECONDARY_CONTEXT);
  841. put_cpu();
  842. }
  843. void smp_flush_tlb_pending(struct mm_struct *mm, unsigned long nr, unsigned long *vaddrs)
  844. {
  845. u32 ctx = CTX_HWBITS(mm->context);
  846. int cpu = get_cpu();
  847. if (mm == current->active_mm && atomic_read(&mm->mm_users) == 1)
  848. mm->cpu_vm_mask = cpumask_of_cpu(cpu);
  849. else
  850. smp_cross_call_masked(&xcall_flush_tlb_pending,
  851. ctx, nr, (unsigned long) vaddrs,
  852. mm->cpu_vm_mask);
  853. __flush_tlb_pending(ctx, nr, vaddrs);
  854. put_cpu();
  855. }
  856. void smp_flush_tlb_kernel_range(unsigned long start, unsigned long end)
  857. {
  858. start &= PAGE_MASK;
  859. end = PAGE_ALIGN(end);
  860. if (start != end) {
  861. smp_cross_call(&xcall_flush_tlb_kernel_range,
  862. 0, start, end);
  863. __flush_tlb_kernel_range(start, end);
  864. }
  865. }
  866. /* CPU capture. */
  867. /* #define CAPTURE_DEBUG */
  868. extern unsigned long xcall_capture;
  869. static atomic_t smp_capture_depth = ATOMIC_INIT(0);
  870. static atomic_t smp_capture_registry = ATOMIC_INIT(0);
  871. static unsigned long penguins_are_doing_time;
  872. void smp_capture(void)
  873. {
  874. int result = atomic_add_ret(1, &smp_capture_depth);
  875. if (result == 1) {
  876. int ncpus = num_online_cpus();
  877. #ifdef CAPTURE_DEBUG
  878. printk("CPU[%d]: Sending penguins to jail...",
  879. smp_processor_id());
  880. #endif
  881. penguins_are_doing_time = 1;
  882. membar_storestore_loadstore();
  883. atomic_inc(&smp_capture_registry);
  884. smp_cross_call(&xcall_capture, 0, 0, 0);
  885. while (atomic_read(&smp_capture_registry) != ncpus)
  886. rmb();
  887. #ifdef CAPTURE_DEBUG
  888. printk("done\n");
  889. #endif
  890. }
  891. }
  892. void smp_release(void)
  893. {
  894. if (atomic_dec_and_test(&smp_capture_depth)) {
  895. #ifdef CAPTURE_DEBUG
  896. printk("CPU[%d]: Giving pardon to "
  897. "imprisoned penguins\n",
  898. smp_processor_id());
  899. #endif
  900. penguins_are_doing_time = 0;
  901. membar_storeload_storestore();
  902. atomic_dec(&smp_capture_registry);
  903. }
  904. }
  905. /* Imprisoned penguins run with %pil == 15, but PSTATE_IE set, so they
  906. * can service tlb flush xcalls...
  907. */
  908. extern void prom_world(int);
  909. void smp_penguin_jailcell(int irq, struct pt_regs *regs)
  910. {
  911. clear_softint(1 << irq);
  912. preempt_disable();
  913. __asm__ __volatile__("flushw");
  914. prom_world(1);
  915. atomic_inc(&smp_capture_registry);
  916. membar_storeload_storestore();
  917. while (penguins_are_doing_time)
  918. rmb();
  919. atomic_dec(&smp_capture_registry);
  920. prom_world(0);
  921. preempt_enable();
  922. }
  923. #define prof_multiplier(__cpu) cpu_data(__cpu).multiplier
  924. #define prof_counter(__cpu) cpu_data(__cpu).counter
  925. void smp_percpu_timer_interrupt(struct pt_regs *regs)
  926. {
  927. unsigned long compare, tick, pstate;
  928. int cpu = smp_processor_id();
  929. int user = user_mode(regs);
  930. /*
  931. * Check for level 14 softint.
  932. */
  933. {
  934. unsigned long tick_mask = tick_ops->softint_mask;
  935. if (!(get_softint() & tick_mask)) {
  936. extern void handler_irq(int, struct pt_regs *);
  937. handler_irq(14, regs);
  938. return;
  939. }
  940. clear_softint(tick_mask);
  941. }
  942. do {
  943. profile_tick(CPU_PROFILING, regs);
  944. if (!--prof_counter(cpu)) {
  945. irq_enter();
  946. if (cpu == boot_cpu_id) {
  947. kstat_this_cpu.irqs[0]++;
  948. timer_tick_interrupt(regs);
  949. }
  950. update_process_times(user);
  951. irq_exit();
  952. prof_counter(cpu) = prof_multiplier(cpu);
  953. }
  954. /* Guarantee that the following sequences execute
  955. * uninterrupted.
  956. */
  957. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  958. "wrpr %0, %1, %%pstate"
  959. : "=r" (pstate)
  960. : "i" (PSTATE_IE));
  961. compare = tick_ops->add_compare(current_tick_offset);
  962. tick = tick_ops->get_tick();
  963. /* Restore PSTATE_IE. */
  964. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  965. : /* no outputs */
  966. : "r" (pstate));
  967. } while (time_after_eq(tick, compare));
  968. }
  969. static void __init smp_setup_percpu_timer(void)
  970. {
  971. int cpu = smp_processor_id();
  972. unsigned long pstate;
  973. prof_counter(cpu) = prof_multiplier(cpu) = 1;
  974. /* Guarantee that the following sequences execute
  975. * uninterrupted.
  976. */
  977. __asm__ __volatile__("rdpr %%pstate, %0\n\t"
  978. "wrpr %0, %1, %%pstate"
  979. : "=r" (pstate)
  980. : "i" (PSTATE_IE));
  981. tick_ops->init_tick(current_tick_offset);
  982. /* Restore PSTATE_IE. */
  983. __asm__ __volatile__("wrpr %0, 0x0, %%pstate"
  984. : /* no outputs */
  985. : "r" (pstate));
  986. }
  987. void __init smp_tick_init(void)
  988. {
  989. boot_cpu_id = hard_smp_processor_id();
  990. current_tick_offset = timer_tick_offset;
  991. cpu_set(boot_cpu_id, cpu_online_map);
  992. prof_counter(boot_cpu_id) = prof_multiplier(boot_cpu_id) = 1;
  993. }
  994. /* /proc/profile writes can call this, don't __init it please. */
  995. static DEFINE_SPINLOCK(prof_setup_lock);
  996. int setup_profiling_timer(unsigned int multiplier)
  997. {
  998. unsigned long flags;
  999. int i;
  1000. if ((!multiplier) || (timer_tick_offset / multiplier) < 1000)
  1001. return -EINVAL;
  1002. spin_lock_irqsave(&prof_setup_lock, flags);
  1003. for (i = 0; i < NR_CPUS; i++)
  1004. prof_multiplier(i) = multiplier;
  1005. current_tick_offset = (timer_tick_offset / multiplier);
  1006. spin_unlock_irqrestore(&prof_setup_lock, flags);
  1007. return 0;
  1008. }
  1009. /* Constrain the number of cpus to max_cpus. */
  1010. void __init smp_prepare_cpus(unsigned int max_cpus)
  1011. {
  1012. if (num_possible_cpus() > max_cpus) {
  1013. int instance, mid;
  1014. instance = 0;
  1015. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  1016. if (mid != boot_cpu_id) {
  1017. cpu_clear(mid, phys_cpu_present_map);
  1018. if (num_possible_cpus() <= max_cpus)
  1019. break;
  1020. }
  1021. instance++;
  1022. }
  1023. }
  1024. smp_store_cpu_info(boot_cpu_id);
  1025. }
  1026. /* Set this up early so that things like the scheduler can init
  1027. * properly. We use the same cpu mask for both the present and
  1028. * possible cpu map.
  1029. */
  1030. void __init smp_setup_cpu_possible_map(void)
  1031. {
  1032. int instance, mid;
  1033. instance = 0;
  1034. while (!cpu_find_by_instance(instance, NULL, &mid)) {
  1035. if (mid < NR_CPUS)
  1036. cpu_set(mid, phys_cpu_present_map);
  1037. instance++;
  1038. }
  1039. }
  1040. void __devinit smp_prepare_boot_cpu(void)
  1041. {
  1042. int cpu = hard_smp_processor_id();
  1043. if (cpu >= NR_CPUS) {
  1044. prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
  1045. prom_halt();
  1046. }
  1047. current_thread_info()->cpu = cpu;
  1048. __local_per_cpu_offset = __per_cpu_offset(cpu);
  1049. cpu_set(smp_processor_id(), cpu_online_map);
  1050. cpu_set(smp_processor_id(), phys_cpu_present_map);
  1051. }
  1052. int __devinit __cpu_up(unsigned int cpu)
  1053. {
  1054. int ret = smp_boot_one_cpu(cpu);
  1055. if (!ret) {
  1056. cpu_set(cpu, smp_commenced_mask);
  1057. while (!cpu_isset(cpu, cpu_online_map))
  1058. mb();
  1059. if (!cpu_isset(cpu, cpu_online_map)) {
  1060. ret = -ENODEV;
  1061. } else {
  1062. /* On SUN4V, writes to %tick and %stick are
  1063. * not allowed.
  1064. */
  1065. if (tlb_type != hypervisor)
  1066. smp_synchronize_one_tick(cpu);
  1067. }
  1068. }
  1069. return ret;
  1070. }
  1071. void __init smp_cpus_done(unsigned int max_cpus)
  1072. {
  1073. unsigned long bogosum = 0;
  1074. int i;
  1075. for (i = 0; i < NR_CPUS; i++) {
  1076. if (cpu_online(i))
  1077. bogosum += cpu_data(i).udelay_val;
  1078. }
  1079. printk("Total of %ld processors activated "
  1080. "(%lu.%02lu BogoMIPS).\n",
  1081. (long) num_online_cpus(),
  1082. bogosum/(500000/HZ),
  1083. (bogosum/(5000/HZ))%100);
  1084. }
  1085. void smp_send_reschedule(int cpu)
  1086. {
  1087. smp_receive_signal(cpu);
  1088. }
  1089. /* This is a nop because we capture all other cpus
  1090. * anyways when making the PROM active.
  1091. */
  1092. void smp_send_stop(void)
  1093. {
  1094. }
  1095. unsigned long __per_cpu_base __read_mostly;
  1096. unsigned long __per_cpu_shift __read_mostly;
  1097. EXPORT_SYMBOL(__per_cpu_base);
  1098. EXPORT_SYMBOL(__per_cpu_shift);
  1099. void __init setup_per_cpu_areas(void)
  1100. {
  1101. unsigned long goal, size, i;
  1102. char *ptr;
  1103. /* Copy section for each CPU (we discard the original) */
  1104. goal = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);
  1105. #ifdef CONFIG_MODULES
  1106. if (goal < PERCPU_ENOUGH_ROOM)
  1107. goal = PERCPU_ENOUGH_ROOM;
  1108. #endif
  1109. __per_cpu_shift = 0;
  1110. for (size = 1UL; size < goal; size <<= 1UL)
  1111. __per_cpu_shift++;
  1112. ptr = alloc_bootmem(size * NR_CPUS);
  1113. __per_cpu_base = ptr - __per_cpu_start;
  1114. for (i = 0; i < NR_CPUS; i++, ptr += size)
  1115. memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
  1116. }