smp.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. /*
  2. * linux/arch/m32r/kernel/smp.c
  3. *
  4. * M32R SMP support routines.
  5. *
  6. * Copyright (c) 2001, 2002 Hitoshi Yamamoto
  7. *
  8. * Taken from i386 version.
  9. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  10. * (c) 1998-99, 2000 Ingo Molnar <mingo@redhat.com>
  11. *
  12. * This code is released under the GNU General Public License version 2 or
  13. * later.
  14. */
  15. #undef DEBUG_SMP
  16. #include <linux/irq.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/sched.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/mm.h>
  21. #include <linux/smp.h>
  22. #include <linux/profile.h>
  23. #include <linux/cpu.h>
  24. #include <asm/cacheflush.h>
  25. #include <asm/pgalloc.h>
  26. #include <linux/atomic.h>
  27. #include <asm/io.h>
  28. #include <asm/mmu_context.h>
  29. #include <asm/m32r.h>
  30. #include <asm/tlbflush.h>
  31. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  32. /* Data structures and variables */
  33. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  34. /*
  35. * For flush_cache_all()
  36. */
  37. static DEFINE_SPINLOCK(flushcache_lock);
  38. static volatile unsigned long flushcache_cpumask = 0;
  39. /*
  40. * For flush_tlb_others()
  41. */
  42. static cpumask_t flush_cpumask;
  43. static struct mm_struct *flush_mm;
  44. static struct vm_area_struct *flush_vma;
  45. static volatile unsigned long flush_va;
  46. static DEFINE_SPINLOCK(tlbstate_lock);
  47. #define FLUSH_ALL 0xffffffff
  48. DECLARE_PER_CPU(int, prof_multiplier);
  49. DECLARE_PER_CPU(int, prof_old_multiplier);
  50. DECLARE_PER_CPU(int, prof_counter);
  51. extern spinlock_t ipi_lock[];
  52. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  53. /* Function Prototypes */
  54. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  55. void smp_reschedule_interrupt(void);
  56. void smp_flush_cache_all_interrupt(void);
  57. static void flush_tlb_all_ipi(void *);
  58. static void flush_tlb_others(cpumask_t, struct mm_struct *,
  59. struct vm_area_struct *, unsigned long);
  60. void smp_invalidate_interrupt(void);
  61. static void stop_this_cpu(void *);
  62. void smp_ipi_timer_interrupt(struct pt_regs *);
  63. void smp_local_timer_interrupt(void);
  64. static void send_IPI_allbutself(int, int);
  65. static void send_IPI_mask(const struct cpumask *, int, int);
  66. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  67. /* Rescheduling request Routines */
  68. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  69. /*==========================================================================*
  70. * Name: smp_send_reschedule
  71. *
  72. * Description: This routine requests other CPU to execute rescheduling.
  73. * 1.Send 'RESCHEDULE_IPI' to other CPU.
  74. * Request other CPU to execute 'smp_reschedule_interrupt()'.
  75. *
  76. * Born on Date: 2002.02.05
  77. *
  78. * Arguments: cpu_id - Target CPU ID
  79. *
  80. * Returns: void (cannot fail)
  81. *
  82. * Modification log:
  83. * Date Who Description
  84. * ---------- --- --------------------------------------------------------
  85. *
  86. *==========================================================================*/
  87. void smp_send_reschedule(int cpu_id)
  88. {
  89. WARN_ON(cpu_is_offline(cpu_id));
  90. send_IPI_mask(cpumask_of(cpu_id), RESCHEDULE_IPI, 1);
  91. }
  92. /*==========================================================================*
  93. * Name: smp_reschedule_interrupt
  94. *
  95. * Description: This routine executes on CPU which received
  96. * 'RESCHEDULE_IPI'.
  97. *
  98. * Born on Date: 2002.02.05
  99. *
  100. * Arguments: NONE
  101. *
  102. * Returns: void (cannot fail)
  103. *
  104. * Modification log:
  105. * Date Who Description
  106. * ---------- --- --------------------------------------------------------
  107. *
  108. *==========================================================================*/
  109. void smp_reschedule_interrupt(void)
  110. {
  111. scheduler_ipi();
  112. }
  113. /*==========================================================================*
  114. * Name: smp_flush_cache_all
  115. *
  116. * Description: This routine sends a 'INVALIDATE_CACHE_IPI' to all other
  117. * CPUs in the system.
  118. *
  119. * Born on Date: 2003-05-28
  120. *
  121. * Arguments: NONE
  122. *
  123. * Returns: void (cannot fail)
  124. *
  125. * Modification log:
  126. * Date Who Description
  127. * ---------- --- --------------------------------------------------------
  128. *
  129. *==========================================================================*/
  130. void smp_flush_cache_all(void)
  131. {
  132. cpumask_t cpumask;
  133. unsigned long *mask;
  134. preempt_disable();
  135. cpumask_copy(&cpumask, cpu_online_mask);
  136. cpumask_clear_cpu(smp_processor_id(), &cpumask);
  137. spin_lock(&flushcache_lock);
  138. mask=cpumask_bits(&cpumask);
  139. atomic_or(*mask, (atomic_t *)&flushcache_cpumask);
  140. send_IPI_mask(&cpumask, INVALIDATE_CACHE_IPI, 0);
  141. _flush_cache_copyback_all();
  142. while (flushcache_cpumask)
  143. mb();
  144. spin_unlock(&flushcache_lock);
  145. preempt_enable();
  146. }
  147. EXPORT_SYMBOL(smp_flush_cache_all);
  148. void smp_flush_cache_all_interrupt(void)
  149. {
  150. _flush_cache_copyback_all();
  151. clear_bit(smp_processor_id(), &flushcache_cpumask);
  152. }
  153. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  154. /* TLB flush request Routines */
  155. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  156. /*==========================================================================*
  157. * Name: smp_flush_tlb_all
  158. *
  159. * Description: This routine flushes all processes TLBs.
  160. * 1.Request other CPU to execute 'flush_tlb_all_ipi()'.
  161. * 2.Execute 'do_flush_tlb_all_local()'.
  162. *
  163. * Born on Date: 2002.02.05
  164. *
  165. * Arguments: NONE
  166. *
  167. * Returns: void (cannot fail)
  168. *
  169. * Modification log:
  170. * Date Who Description
  171. * ---------- --- --------------------------------------------------------
  172. *
  173. *==========================================================================*/
  174. void smp_flush_tlb_all(void)
  175. {
  176. unsigned long flags;
  177. preempt_disable();
  178. local_irq_save(flags);
  179. __flush_tlb_all();
  180. local_irq_restore(flags);
  181. smp_call_function(flush_tlb_all_ipi, NULL, 1);
  182. preempt_enable();
  183. }
  184. /*==========================================================================*
  185. * Name: flush_tlb_all_ipi
  186. *
  187. * Description: This routine flushes all local TLBs.
  188. * 1.Execute 'do_flush_tlb_all_local()'.
  189. *
  190. * Born on Date: 2002.02.05
  191. *
  192. * Arguments: *info - not used
  193. *
  194. * Returns: void (cannot fail)
  195. *
  196. * Modification log:
  197. * Date Who Description
  198. * ---------- --- --------------------------------------------------------
  199. *
  200. *==========================================================================*/
  201. static void flush_tlb_all_ipi(void *info)
  202. {
  203. __flush_tlb_all();
  204. }
  205. /*==========================================================================*
  206. * Name: smp_flush_tlb_mm
  207. *
  208. * Description: This routine flushes the specified mm context TLB's.
  209. *
  210. * Born on Date: 2002.02.05
  211. *
  212. * Arguments: *mm - a pointer to the mm struct for flush TLB
  213. *
  214. * Returns: void (cannot fail)
  215. *
  216. * Modification log:
  217. * Date Who Description
  218. * ---------- --- --------------------------------------------------------
  219. *
  220. *==========================================================================*/
  221. void smp_flush_tlb_mm(struct mm_struct *mm)
  222. {
  223. int cpu_id;
  224. cpumask_t cpu_mask;
  225. unsigned long *mmc;
  226. unsigned long flags;
  227. preempt_disable();
  228. cpu_id = smp_processor_id();
  229. mmc = &mm->context[cpu_id];
  230. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  231. cpumask_clear_cpu(cpu_id, &cpu_mask);
  232. if (*mmc != NO_CONTEXT) {
  233. local_irq_save(flags);
  234. *mmc = NO_CONTEXT;
  235. if (mm == current->mm)
  236. activate_context(mm);
  237. else
  238. cpumask_clear_cpu(cpu_id, mm_cpumask(mm));
  239. local_irq_restore(flags);
  240. }
  241. if (!cpumask_empty(&cpu_mask))
  242. flush_tlb_others(cpu_mask, mm, NULL, FLUSH_ALL);
  243. preempt_enable();
  244. }
  245. /*==========================================================================*
  246. * Name: smp_flush_tlb_range
  247. *
  248. * Description: This routine flushes a range of pages.
  249. *
  250. * Born on Date: 2002.02.05
  251. *
  252. * Arguments: *mm - a pointer to the mm struct for flush TLB
  253. * start - not used
  254. * end - not used
  255. *
  256. * Returns: void (cannot fail)
  257. *
  258. * Modification log:
  259. * Date Who Description
  260. * ---------- --- --------------------------------------------------------
  261. *
  262. *==========================================================================*/
  263. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  264. unsigned long end)
  265. {
  266. smp_flush_tlb_mm(vma->vm_mm);
  267. }
  268. /*==========================================================================*
  269. * Name: smp_flush_tlb_page
  270. *
  271. * Description: This routine flushes one page.
  272. *
  273. * Born on Date: 2002.02.05
  274. *
  275. * Arguments: *vma - a pointer to the vma struct include va
  276. * va - virtual address for flush TLB
  277. *
  278. * Returns: void (cannot fail)
  279. *
  280. * Modification log:
  281. * Date Who Description
  282. * ---------- --- --------------------------------------------------------
  283. *
  284. *==========================================================================*/
  285. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long va)
  286. {
  287. struct mm_struct *mm = vma->vm_mm;
  288. int cpu_id;
  289. cpumask_t cpu_mask;
  290. unsigned long *mmc;
  291. unsigned long flags;
  292. preempt_disable();
  293. cpu_id = smp_processor_id();
  294. mmc = &mm->context[cpu_id];
  295. cpumask_copy(&cpu_mask, mm_cpumask(mm));
  296. cpumask_clear_cpu(cpu_id, &cpu_mask);
  297. #ifdef DEBUG_SMP
  298. if (!mm)
  299. BUG();
  300. #endif
  301. if (*mmc != NO_CONTEXT) {
  302. local_irq_save(flags);
  303. va &= PAGE_MASK;
  304. va |= (*mmc & MMU_CONTEXT_ASID_MASK);
  305. __flush_tlb_page(va);
  306. local_irq_restore(flags);
  307. }
  308. if (!cpumask_empty(&cpu_mask))
  309. flush_tlb_others(cpu_mask, mm, vma, va);
  310. preempt_enable();
  311. }
  312. /*==========================================================================*
  313. * Name: flush_tlb_others
  314. *
  315. * Description: This routine requests other CPU to execute flush TLB.
  316. * 1.Setup parameters.
  317. * 2.Send 'INVALIDATE_TLB_IPI' to other CPU.
  318. * Request other CPU to execute 'smp_invalidate_interrupt()'.
  319. * 3.Wait for other CPUs operation finished.
  320. *
  321. * Born on Date: 2002.02.05
  322. *
  323. * Arguments: cpumask - bitmap of target CPUs
  324. * *mm - a pointer to the mm struct for flush TLB
  325. * *vma - a pointer to the vma struct include va
  326. * va - virtual address for flush TLB
  327. *
  328. * Returns: void (cannot fail)
  329. *
  330. * Modification log:
  331. * Date Who Description
  332. * ---------- --- --------------------------------------------------------
  333. *
  334. *==========================================================================*/
  335. static void flush_tlb_others(cpumask_t cpumask, struct mm_struct *mm,
  336. struct vm_area_struct *vma, unsigned long va)
  337. {
  338. unsigned long *mask;
  339. #ifdef DEBUG_SMP
  340. unsigned long flags;
  341. __save_flags(flags);
  342. if (!(flags & 0x0040)) /* Interrupt Disable NONONO */
  343. BUG();
  344. #endif /* DEBUG_SMP */
  345. /*
  346. * A couple of (to be removed) sanity checks:
  347. *
  348. * - we do not send IPIs to not-yet booted CPUs.
  349. * - current CPU must not be in mask
  350. * - mask must exist :)
  351. */
  352. BUG_ON(cpumask_empty(&cpumask));
  353. BUG_ON(cpumask_test_cpu(smp_processor_id(), &cpumask));
  354. BUG_ON(!mm);
  355. /* If a CPU which we ran on has gone down, OK. */
  356. cpumask_and(&cpumask, &cpumask, cpu_online_mask);
  357. if (cpumask_empty(&cpumask))
  358. return;
  359. /*
  360. * i'm not happy about this global shared spinlock in the
  361. * MM hot path, but we'll see how contended it is.
  362. * Temporarily this turns IRQs off, so that lockups are
  363. * detected by the NMI watchdog.
  364. */
  365. spin_lock(&tlbstate_lock);
  366. flush_mm = mm;
  367. flush_vma = vma;
  368. flush_va = va;
  369. mask=cpumask_bits(&cpumask);
  370. atomic_or(*mask, (atomic_t *)&flush_cpumask);
  371. /*
  372. * We have to send the IPI only to
  373. * CPUs affected.
  374. */
  375. send_IPI_mask(&cpumask, INVALIDATE_TLB_IPI, 0);
  376. while (!cpumask_empty(&flush_cpumask)) {
  377. /* nothing. lockup detection does not belong here */
  378. mb();
  379. }
  380. flush_mm = NULL;
  381. flush_vma = NULL;
  382. flush_va = 0;
  383. spin_unlock(&tlbstate_lock);
  384. }
  385. /*==========================================================================*
  386. * Name: smp_invalidate_interrupt
  387. *
  388. * Description: This routine executes on CPU which received
  389. * 'INVALIDATE_TLB_IPI'.
  390. * 1.Flush local TLB.
  391. * 2.Report flush TLB process was finished.
  392. *
  393. * Born on Date: 2002.02.05
  394. *
  395. * Arguments: NONE
  396. *
  397. * Returns: void (cannot fail)
  398. *
  399. * Modification log:
  400. * Date Who Description
  401. * ---------- --- --------------------------------------------------------
  402. *
  403. *==========================================================================*/
  404. void smp_invalidate_interrupt(void)
  405. {
  406. int cpu_id = smp_processor_id();
  407. unsigned long *mmc = &flush_mm->context[cpu_id];
  408. if (!cpumask_test_cpu(cpu_id, &flush_cpumask))
  409. return;
  410. if (flush_va == FLUSH_ALL) {
  411. *mmc = NO_CONTEXT;
  412. if (flush_mm == current->active_mm)
  413. activate_context(flush_mm);
  414. else
  415. cpumask_clear_cpu(cpu_id, mm_cpumask(flush_mm));
  416. } else {
  417. unsigned long va = flush_va;
  418. if (*mmc != NO_CONTEXT) {
  419. va &= PAGE_MASK;
  420. va |= (*mmc & MMU_CONTEXT_ASID_MASK);
  421. __flush_tlb_page(va);
  422. }
  423. }
  424. cpumask_clear_cpu(cpu_id, &flush_cpumask);
  425. }
  426. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  427. /* Stop CPU request Routines */
  428. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  429. /*==========================================================================*
  430. * Name: smp_send_stop
  431. *
  432. * Description: This routine requests stop all CPUs.
  433. * 1.Request other CPU to execute 'stop_this_cpu()'.
  434. *
  435. * Born on Date: 2002.02.05
  436. *
  437. * Arguments: NONE
  438. *
  439. * Returns: void (cannot fail)
  440. *
  441. * Modification log:
  442. * Date Who Description
  443. * ---------- --- --------------------------------------------------------
  444. *
  445. *==========================================================================*/
  446. void smp_send_stop(void)
  447. {
  448. smp_call_function(stop_this_cpu, NULL, 0);
  449. }
  450. /*==========================================================================*
  451. * Name: stop_this_cpu
  452. *
  453. * Description: This routine halt CPU.
  454. *
  455. * Born on Date: 2002.02.05
  456. *
  457. * Arguments: NONE
  458. *
  459. * Returns: void (cannot fail)
  460. *
  461. * Modification log:
  462. * Date Who Description
  463. * ---------- --- --------------------------------------------------------
  464. *
  465. *==========================================================================*/
  466. static void stop_this_cpu(void *dummy)
  467. {
  468. int cpu_id = smp_processor_id();
  469. /*
  470. * Remove this CPU:
  471. */
  472. set_cpu_online(cpu_id, false);
  473. /*
  474. * PSW IE = 1;
  475. * IMASK = 0;
  476. * goto SLEEP
  477. */
  478. local_irq_disable();
  479. outl(0, M32R_ICU_IMASK_PORTL);
  480. inl(M32R_ICU_IMASK_PORTL); /* dummy read */
  481. local_irq_enable();
  482. for ( ; ; );
  483. }
  484. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  485. {
  486. send_IPI_mask(mask, CALL_FUNCTION_IPI, 0);
  487. }
  488. void arch_send_call_function_single_ipi(int cpu)
  489. {
  490. send_IPI_mask(cpumask_of(cpu), CALL_FUNC_SINGLE_IPI, 0);
  491. }
  492. /*==========================================================================*
  493. * Name: smp_call_function_interrupt
  494. *
  495. * Description: This routine executes on CPU which received
  496. * 'CALL_FUNCTION_IPI'.
  497. *
  498. * Born on Date: 2002.02.05
  499. *
  500. * Arguments: NONE
  501. *
  502. * Returns: void (cannot fail)
  503. *
  504. * Modification log:
  505. * Date Who Description
  506. * ---------- --- --------------------------------------------------------
  507. *
  508. *==========================================================================*/
  509. void smp_call_function_interrupt(void)
  510. {
  511. irq_enter();
  512. generic_smp_call_function_interrupt();
  513. irq_exit();
  514. }
  515. void smp_call_function_single_interrupt(void)
  516. {
  517. irq_enter();
  518. generic_smp_call_function_single_interrupt();
  519. irq_exit();
  520. }
  521. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  522. /* Timer Routines */
  523. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  524. /*==========================================================================*
  525. * Name: smp_send_timer
  526. *
  527. * Description: This routine sends a 'LOCAL_TIMER_IPI' to all other CPUs
  528. * in the system.
  529. *
  530. * Born on Date: 2002.02.05
  531. *
  532. * Arguments: NONE
  533. *
  534. * Returns: void (cannot fail)
  535. *
  536. * Modification log:
  537. * Date Who Description
  538. * ---------- --- --------------------------------------------------------
  539. *
  540. *==========================================================================*/
  541. void smp_send_timer(void)
  542. {
  543. send_IPI_allbutself(LOCAL_TIMER_IPI, 1);
  544. }
  545. /*==========================================================================*
  546. * Name: smp_send_timer
  547. *
  548. * Description: This routine executes on CPU which received
  549. * 'LOCAL_TIMER_IPI'.
  550. *
  551. * Born on Date: 2002.02.05
  552. *
  553. * Arguments: *regs - a pointer to the saved regster info
  554. *
  555. * Returns: void (cannot fail)
  556. *
  557. * Modification log:
  558. * Date Who Description
  559. * ---------- --- --------------------------------------------------------
  560. *
  561. *==========================================================================*/
  562. void smp_ipi_timer_interrupt(struct pt_regs *regs)
  563. {
  564. struct pt_regs *old_regs;
  565. old_regs = set_irq_regs(regs);
  566. irq_enter();
  567. smp_local_timer_interrupt();
  568. irq_exit();
  569. set_irq_regs(old_regs);
  570. }
  571. /*==========================================================================*
  572. * Name: smp_local_timer_interrupt
  573. *
  574. * Description: Local timer interrupt handler. It does both profiling and
  575. * process statistics/rescheduling.
  576. * We do profiling in every local tick, statistics/rescheduling
  577. * happen only every 'profiling multiplier' ticks. The default
  578. * multiplier is 1 and it can be changed by writing the new
  579. * multiplier value into /proc/profile.
  580. *
  581. * Born on Date: 2002.02.05
  582. *
  583. * Arguments: *regs - a pointer to the saved regster info
  584. *
  585. * Returns: void (cannot fail)
  586. *
  587. * Original: arch/i386/kernel/apic.c
  588. *
  589. * Modification log:
  590. * Date Who Description
  591. * ---------- --- --------------------------------------------------------
  592. * 2003-06-24 hy use per_cpu structure.
  593. *==========================================================================*/
  594. void smp_local_timer_interrupt(void)
  595. {
  596. int user = user_mode(get_irq_regs());
  597. int cpu_id = smp_processor_id();
  598. /*
  599. * The profiling function is SMP safe. (nothing can mess
  600. * around with "current", and the profiling counters are
  601. * updated with atomic operations). This is especially
  602. * useful with a profiling multiplier != 1
  603. */
  604. profile_tick(CPU_PROFILING);
  605. if (--per_cpu(prof_counter, cpu_id) <= 0) {
  606. /*
  607. * The multiplier may have changed since the last time we got
  608. * to this point as a result of the user writing to
  609. * /proc/profile. In this case we need to adjust the APIC
  610. * timer accordingly.
  611. *
  612. * Interrupts are already masked off at this point.
  613. */
  614. per_cpu(prof_counter, cpu_id)
  615. = per_cpu(prof_multiplier, cpu_id);
  616. if (per_cpu(prof_counter, cpu_id)
  617. != per_cpu(prof_old_multiplier, cpu_id))
  618. {
  619. per_cpu(prof_old_multiplier, cpu_id)
  620. = per_cpu(prof_counter, cpu_id);
  621. }
  622. update_process_times(user);
  623. }
  624. }
  625. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  626. /* Send IPI Routines */
  627. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  628. /*==========================================================================*
  629. * Name: send_IPI_allbutself
  630. *
  631. * Description: This routine sends a IPI to all other CPUs in the system.
  632. *
  633. * Born on Date: 2002.02.05
  634. *
  635. * Arguments: ipi_num - Number of IPI
  636. * try - 0 : Send IPI certainly.
  637. * !0 : The following IPI is not sent when Target CPU
  638. * has not received the before IPI.
  639. *
  640. * Returns: void (cannot fail)
  641. *
  642. * Modification log:
  643. * Date Who Description
  644. * ---------- --- --------------------------------------------------------
  645. *
  646. *==========================================================================*/
  647. static void send_IPI_allbutself(int ipi_num, int try)
  648. {
  649. cpumask_t cpumask;
  650. cpumask_copy(&cpumask, cpu_online_mask);
  651. cpumask_clear_cpu(smp_processor_id(), &cpumask);
  652. send_IPI_mask(&cpumask, ipi_num, try);
  653. }
  654. /*==========================================================================*
  655. * Name: send_IPI_mask
  656. *
  657. * Description: This routine sends a IPI to CPUs in the system.
  658. *
  659. * Born on Date: 2002.02.05
  660. *
  661. * Arguments: cpu_mask - Bitmap of target CPUs logical ID
  662. * ipi_num - Number of IPI
  663. * try - 0 : Send IPI certainly.
  664. * !0 : The following IPI is not sent when Target CPU
  665. * has not received the before IPI.
  666. *
  667. * Returns: void (cannot fail)
  668. *
  669. * Modification log:
  670. * Date Who Description
  671. * ---------- --- --------------------------------------------------------
  672. *
  673. *==========================================================================*/
  674. static void send_IPI_mask(const struct cpumask *cpumask, int ipi_num, int try)
  675. {
  676. cpumask_t physid_mask, tmp;
  677. int cpu_id, phys_id;
  678. int num_cpus = num_online_cpus();
  679. if (num_cpus <= 1) /* NO MP */
  680. return;
  681. cpumask_and(&tmp, cpumask, cpu_online_mask);
  682. BUG_ON(!cpumask_equal(cpumask, &tmp));
  683. cpumask_clear(&physid_mask);
  684. for_each_cpu(cpu_id, cpumask) {
  685. if ((phys_id = cpu_to_physid(cpu_id)) != -1)
  686. cpumask_set_cpu(phys_id, &physid_mask);
  687. }
  688. send_IPI_mask_phys(&physid_mask, ipi_num, try);
  689. }
  690. /*==========================================================================*
  691. * Name: send_IPI_mask_phys
  692. *
  693. * Description: This routine sends a IPI to other CPUs in the system.
  694. *
  695. * Born on Date: 2002.02.05
  696. *
  697. * Arguments: cpu_mask - Bitmap of target CPUs physical ID
  698. * ipi_num - Number of IPI
  699. * try - 0 : Send IPI certainly.
  700. * !0 : The following IPI is not sent when Target CPU
  701. * has not received the before IPI.
  702. *
  703. * Returns: IPICRi regster value.
  704. *
  705. * Modification log:
  706. * Date Who Description
  707. * ---------- --- --------------------------------------------------------
  708. *
  709. *==========================================================================*/
  710. unsigned long send_IPI_mask_phys(const cpumask_t *physid_mask, int ipi_num,
  711. int try)
  712. {
  713. spinlock_t *ipilock;
  714. volatile unsigned long *ipicr_addr;
  715. unsigned long ipicr_val;
  716. unsigned long my_physid_mask;
  717. unsigned long mask = cpumask_bits(physid_mask)[0];
  718. if (mask & ~physids_coerce(phys_cpu_present_map))
  719. BUG();
  720. if (ipi_num >= NR_IPIS || ipi_num < 0)
  721. BUG();
  722. mask <<= IPI_SHIFT;
  723. ipilock = &ipi_lock[ipi_num];
  724. ipicr_addr = (volatile unsigned long *)(M32R_ICU_IPICR_ADDR
  725. + (ipi_num << 2));
  726. my_physid_mask = ~(1 << smp_processor_id());
  727. /*
  728. * lock ipi_lock[i]
  729. * check IPICRi == 0
  730. * write IPICRi (send IPIi)
  731. * unlock ipi_lock[i]
  732. */
  733. spin_lock(ipilock);
  734. __asm__ __volatile__ (
  735. ";; CHECK IPICRi == 0 \n\t"
  736. ".fillinsn \n"
  737. "1: \n\t"
  738. "ld %0, @%1 \n\t"
  739. "and %0, %4 \n\t"
  740. "beqz %0, 2f \n\t"
  741. "bnez %3, 3f \n\t"
  742. "bra 1b \n\t"
  743. ";; WRITE IPICRi (send IPIi) \n\t"
  744. ".fillinsn \n"
  745. "2: \n\t"
  746. "st %2, @%1 \n\t"
  747. ".fillinsn \n"
  748. "3: \n\t"
  749. : "=&r"(ipicr_val)
  750. : "r"(ipicr_addr), "r"(mask), "r"(try), "r"(my_physid_mask)
  751. : "memory"
  752. );
  753. spin_unlock(ipilock);
  754. return ipicr_val;
  755. }