smp.c 32 KB

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