process.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/preempt.h>
  16. #include <linux/module.h>
  17. #include <linux/fs.h>
  18. #include <linux/kprobes.h>
  19. #include <linux/elfcore.h>
  20. #include <linux/tick.h>
  21. #include <linux/init.h>
  22. #include <linux/mm.h>
  23. #include <linux/compat.h>
  24. #include <linux/hardirq.h>
  25. #include <linux/syscalls.h>
  26. #include <linux/kernel.h>
  27. #include <linux/tracehook.h>
  28. #include <linux/signal.h>
  29. #include <asm/stack.h>
  30. #include <asm/switch_to.h>
  31. #include <asm/homecache.h>
  32. #include <asm/syscalls.h>
  33. #include <asm/traps.h>
  34. #include <asm/setup.h>
  35. #ifdef CONFIG_HARDWALL
  36. #include <asm/hardwall.h>
  37. #endif
  38. #include <arch/chip.h>
  39. #include <arch/abi.h>
  40. #include <arch/sim_def.h>
  41. /*
  42. * Use the (x86) "idle=poll" option to prefer low latency when leaving the
  43. * idle loop over low power while in the idle loop, e.g. if we have
  44. * one thread per core and we want to get threads out of futex waits fast.
  45. */
  46. static int __init idle_setup(char *str)
  47. {
  48. if (!str)
  49. return -EINVAL;
  50. if (!strcmp(str, "poll")) {
  51. pr_info("using polling idle threads.\n");
  52. cpu_idle_poll_ctrl(true);
  53. return 0;
  54. } else if (!strcmp(str, "halt")) {
  55. return 0;
  56. }
  57. return -1;
  58. }
  59. early_param("idle", idle_setup);
  60. void arch_cpu_idle(void)
  61. {
  62. __get_cpu_var(irq_stat).idle_timestamp = jiffies;
  63. _cpu_idle();
  64. }
  65. /*
  66. * Release a thread_info structure
  67. */
  68. void arch_release_thread_info(struct thread_info *info)
  69. {
  70. struct single_step_state *step_state = info->step_state;
  71. if (step_state) {
  72. /*
  73. * FIXME: we don't munmap step_state->buffer
  74. * because the mm_struct for this process (info->task->mm)
  75. * has already been zeroed in exit_mm(). Keeping a
  76. * reference to it here seems like a bad move, so this
  77. * means we can't munmap() the buffer, and therefore if we
  78. * ptrace multiple threads in a process, we will slowly
  79. * leak user memory. (Note that as soon as the last
  80. * thread in a process dies, we will reclaim all user
  81. * memory including single-step buffers in the usual way.)
  82. * We should either assign a kernel VA to this buffer
  83. * somehow, or we should associate the buffer(s) with the
  84. * mm itself so we can clean them up that way.
  85. */
  86. kfree(step_state);
  87. }
  88. }
  89. static void save_arch_state(struct thread_struct *t);
  90. int copy_thread(unsigned long clone_flags, unsigned long sp,
  91. unsigned long arg, struct task_struct *p)
  92. {
  93. struct pt_regs *childregs = task_pt_regs(p);
  94. unsigned long ksp;
  95. unsigned long *callee_regs;
  96. /*
  97. * Set up the stack and stack pointer appropriately for the
  98. * new child to find itself woken up in __switch_to().
  99. * The callee-saved registers must be on the stack to be read;
  100. * the new task will then jump to assembly support to handle
  101. * calling schedule_tail(), etc., and (for userspace tasks)
  102. * returning to the context set up in the pt_regs.
  103. */
  104. ksp = (unsigned long) childregs;
  105. ksp -= C_ABI_SAVE_AREA_SIZE; /* interrupt-entry save area */
  106. ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
  107. ksp -= CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long);
  108. callee_regs = (unsigned long *)ksp;
  109. ksp -= C_ABI_SAVE_AREA_SIZE; /* __switch_to() save area */
  110. ((long *)ksp)[0] = ((long *)ksp)[1] = 0;
  111. p->thread.ksp = ksp;
  112. /* Record the pid of the task that created this one. */
  113. p->thread.creator_pid = current->pid;
  114. if (unlikely(p->flags & PF_KTHREAD)) {
  115. /* kernel thread */
  116. memset(childregs, 0, sizeof(struct pt_regs));
  117. memset(&callee_regs[2], 0,
  118. (CALLEE_SAVED_REGS_COUNT - 2) * sizeof(unsigned long));
  119. callee_regs[0] = sp; /* r30 = function */
  120. callee_regs[1] = arg; /* r31 = arg */
  121. childregs->ex1 = PL_ICS_EX1(KERNEL_PL, 0);
  122. p->thread.pc = (unsigned long) ret_from_kernel_thread;
  123. return 0;
  124. }
  125. /*
  126. * Start new thread in ret_from_fork so it schedules properly
  127. * and then return from interrupt like the parent.
  128. */
  129. p->thread.pc = (unsigned long) ret_from_fork;
  130. /*
  131. * Do not clone step state from the parent; each thread
  132. * must make its own lazily.
  133. */
  134. task_thread_info(p)->step_state = NULL;
  135. /*
  136. * Copy the registers onto the kernel stack so the
  137. * return-from-interrupt code will reload it into registers.
  138. */
  139. *childregs = *current_pt_regs();
  140. childregs->regs[0] = 0; /* return value is zero */
  141. if (sp)
  142. childregs->sp = sp; /* override with new user stack pointer */
  143. memcpy(callee_regs, &childregs->regs[CALLEE_SAVED_FIRST_REG],
  144. CALLEE_SAVED_REGS_COUNT * sizeof(unsigned long));
  145. /* Save user stack top pointer so we can ID the stack vm area later. */
  146. p->thread.usp0 = childregs->sp;
  147. /*
  148. * If CLONE_SETTLS is set, set "tp" in the new task to "r4",
  149. * which is passed in as arg #5 to sys_clone().
  150. */
  151. if (clone_flags & CLONE_SETTLS)
  152. childregs->tp = childregs->regs[4];
  153. #if CHIP_HAS_TILE_DMA()
  154. /*
  155. * No DMA in the new thread. We model this on the fact that
  156. * fork() clears the pending signals, alarms, and aio for the child.
  157. */
  158. memset(&p->thread.tile_dma_state, 0, sizeof(struct tile_dma_state));
  159. memset(&p->thread.dma_async_tlb, 0, sizeof(struct async_tlb));
  160. #endif
  161. #if CHIP_HAS_SN_PROC()
  162. /* Likewise, the new thread is not running static processor code. */
  163. p->thread.sn_proc_running = 0;
  164. memset(&p->thread.sn_async_tlb, 0, sizeof(struct async_tlb));
  165. #endif
  166. #if CHIP_HAS_PROC_STATUS_SPR()
  167. /* New thread has its miscellaneous processor state bits clear. */
  168. p->thread.proc_status = 0;
  169. #endif
  170. #ifdef CONFIG_HARDWALL
  171. /* New thread does not own any networks. */
  172. memset(&p->thread.hardwall[0], 0,
  173. sizeof(struct hardwall_task) * HARDWALL_TYPES);
  174. #endif
  175. /*
  176. * Start the new thread with the current architecture state
  177. * (user interrupt masks, etc.).
  178. */
  179. save_arch_state(&p->thread);
  180. return 0;
  181. }
  182. /*
  183. * Return "current" if it looks plausible, or else a pointer to a dummy.
  184. * This can be helpful if we are just trying to emit a clean panic.
  185. */
  186. struct task_struct *validate_current(void)
  187. {
  188. static struct task_struct corrupt = { .comm = "<corrupt>" };
  189. struct task_struct *tsk = current;
  190. if (unlikely((unsigned long)tsk < PAGE_OFFSET ||
  191. (high_memory && (void *)tsk > high_memory) ||
  192. ((unsigned long)tsk & (__alignof__(*tsk) - 1)) != 0)) {
  193. pr_err("Corrupt 'current' %p (sp %#lx)\n", tsk, stack_pointer);
  194. tsk = &corrupt;
  195. }
  196. return tsk;
  197. }
  198. /* Take and return the pointer to the previous task, for schedule_tail(). */
  199. struct task_struct *sim_notify_fork(struct task_struct *prev)
  200. {
  201. struct task_struct *tsk = current;
  202. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK_PARENT |
  203. (tsk->thread.creator_pid << _SIM_CONTROL_OPERATOR_BITS));
  204. __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_OS_FORK |
  205. (tsk->pid << _SIM_CONTROL_OPERATOR_BITS));
  206. return prev;
  207. }
  208. int dump_task_regs(struct task_struct *tsk, elf_gregset_t *regs)
  209. {
  210. struct pt_regs *ptregs = task_pt_regs(tsk);
  211. elf_core_copy_regs(regs, ptregs);
  212. return 1;
  213. }
  214. #if CHIP_HAS_TILE_DMA()
  215. /* Allow user processes to access the DMA SPRs */
  216. void grant_dma_mpls(void)
  217. {
  218. #if CONFIG_KERNEL_PL == 2
  219. __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
  220. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
  221. #else
  222. __insn_mtspr(SPR_MPL_DMA_CPL_SET_0, 1);
  223. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_0, 1);
  224. #endif
  225. }
  226. /* Forbid user processes from accessing the DMA SPRs */
  227. void restrict_dma_mpls(void)
  228. {
  229. #if CONFIG_KERNEL_PL == 2
  230. __insn_mtspr(SPR_MPL_DMA_CPL_SET_2, 1);
  231. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_2, 1);
  232. #else
  233. __insn_mtspr(SPR_MPL_DMA_CPL_SET_1, 1);
  234. __insn_mtspr(SPR_MPL_DMA_NOTIFY_SET_1, 1);
  235. #endif
  236. }
  237. /* Pause the DMA engine, then save off its state registers. */
  238. static void save_tile_dma_state(struct tile_dma_state *dma)
  239. {
  240. unsigned long state = __insn_mfspr(SPR_DMA_USER_STATUS);
  241. unsigned long post_suspend_state;
  242. /* If we're running, suspend the engine. */
  243. if ((state & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK)
  244. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__SUSPEND_MASK);
  245. /*
  246. * Wait for the engine to idle, then save regs. Note that we
  247. * want to record the "running" bit from before suspension,
  248. * and the "done" bit from after, so that we can properly
  249. * distinguish a case where the user suspended the engine from
  250. * the case where the kernel suspended as part of the context
  251. * swap.
  252. */
  253. do {
  254. post_suspend_state = __insn_mfspr(SPR_DMA_USER_STATUS);
  255. } while (post_suspend_state & SPR_DMA_STATUS__BUSY_MASK);
  256. dma->src = __insn_mfspr(SPR_DMA_SRC_ADDR);
  257. dma->src_chunk = __insn_mfspr(SPR_DMA_SRC_CHUNK_ADDR);
  258. dma->dest = __insn_mfspr(SPR_DMA_DST_ADDR);
  259. dma->dest_chunk = __insn_mfspr(SPR_DMA_DST_CHUNK_ADDR);
  260. dma->strides = __insn_mfspr(SPR_DMA_STRIDE);
  261. dma->chunk_size = __insn_mfspr(SPR_DMA_CHUNK_SIZE);
  262. dma->byte = __insn_mfspr(SPR_DMA_BYTE);
  263. dma->status = (state & SPR_DMA_STATUS__RUNNING_MASK) |
  264. (post_suspend_state & SPR_DMA_STATUS__DONE_MASK);
  265. }
  266. /* Restart a DMA that was running before we were context-switched out. */
  267. static void restore_tile_dma_state(struct thread_struct *t)
  268. {
  269. const struct tile_dma_state *dma = &t->tile_dma_state;
  270. /*
  271. * The only way to restore the done bit is to run a zero
  272. * length transaction.
  273. */
  274. if ((dma->status & SPR_DMA_STATUS__DONE_MASK) &&
  275. !(__insn_mfspr(SPR_DMA_USER_STATUS) & SPR_DMA_STATUS__DONE_MASK)) {
  276. __insn_mtspr(SPR_DMA_BYTE, 0);
  277. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
  278. while (__insn_mfspr(SPR_DMA_USER_STATUS) &
  279. SPR_DMA_STATUS__BUSY_MASK)
  280. ;
  281. }
  282. __insn_mtspr(SPR_DMA_SRC_ADDR, dma->src);
  283. __insn_mtspr(SPR_DMA_SRC_CHUNK_ADDR, dma->src_chunk);
  284. __insn_mtspr(SPR_DMA_DST_ADDR, dma->dest);
  285. __insn_mtspr(SPR_DMA_DST_CHUNK_ADDR, dma->dest_chunk);
  286. __insn_mtspr(SPR_DMA_STRIDE, dma->strides);
  287. __insn_mtspr(SPR_DMA_CHUNK_SIZE, dma->chunk_size);
  288. __insn_mtspr(SPR_DMA_BYTE, dma->byte);
  289. /*
  290. * Restart the engine if we were running and not done.
  291. * Clear a pending async DMA fault that we were waiting on return
  292. * to user space to execute, since we expect the DMA engine
  293. * to regenerate those faults for us now. Note that we don't
  294. * try to clear the TIF_ASYNC_TLB flag, since it's relatively
  295. * harmless if set, and it covers both DMA and the SN processor.
  296. */
  297. if ((dma->status & DMA_STATUS_MASK) == SPR_DMA_STATUS__RUNNING_MASK) {
  298. t->dma_async_tlb.fault_num = 0;
  299. __insn_mtspr(SPR_DMA_CTR, SPR_DMA_CTR__REQUEST_MASK);
  300. }
  301. }
  302. #endif
  303. static void save_arch_state(struct thread_struct *t)
  304. {
  305. #if CHIP_HAS_SPLIT_INTR_MASK()
  306. t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0_0) |
  307. ((u64)__insn_mfspr(SPR_INTERRUPT_MASK_0_1) << 32);
  308. #else
  309. t->interrupt_mask = __insn_mfspr(SPR_INTERRUPT_MASK_0);
  310. #endif
  311. t->ex_context[0] = __insn_mfspr(SPR_EX_CONTEXT_0_0);
  312. t->ex_context[1] = __insn_mfspr(SPR_EX_CONTEXT_0_1);
  313. t->system_save[0] = __insn_mfspr(SPR_SYSTEM_SAVE_0_0);
  314. t->system_save[1] = __insn_mfspr(SPR_SYSTEM_SAVE_0_1);
  315. t->system_save[2] = __insn_mfspr(SPR_SYSTEM_SAVE_0_2);
  316. t->system_save[3] = __insn_mfspr(SPR_SYSTEM_SAVE_0_3);
  317. t->intctrl_0 = __insn_mfspr(SPR_INTCTRL_0_STATUS);
  318. #if CHIP_HAS_PROC_STATUS_SPR()
  319. t->proc_status = __insn_mfspr(SPR_PROC_STATUS);
  320. #endif
  321. #if !CHIP_HAS_FIXED_INTVEC_BASE()
  322. t->interrupt_vector_base = __insn_mfspr(SPR_INTERRUPT_VECTOR_BASE_0);
  323. #endif
  324. #if CHIP_HAS_TILE_RTF_HWM()
  325. t->tile_rtf_hwm = __insn_mfspr(SPR_TILE_RTF_HWM);
  326. #endif
  327. #if CHIP_HAS_DSTREAM_PF()
  328. t->dstream_pf = __insn_mfspr(SPR_DSTREAM_PF);
  329. #endif
  330. }
  331. static void restore_arch_state(const struct thread_struct *t)
  332. {
  333. #if CHIP_HAS_SPLIT_INTR_MASK()
  334. __insn_mtspr(SPR_INTERRUPT_MASK_0_0, (u32) t->interrupt_mask);
  335. __insn_mtspr(SPR_INTERRUPT_MASK_0_1, t->interrupt_mask >> 32);
  336. #else
  337. __insn_mtspr(SPR_INTERRUPT_MASK_0, t->interrupt_mask);
  338. #endif
  339. __insn_mtspr(SPR_EX_CONTEXT_0_0, t->ex_context[0]);
  340. __insn_mtspr(SPR_EX_CONTEXT_0_1, t->ex_context[1]);
  341. __insn_mtspr(SPR_SYSTEM_SAVE_0_0, t->system_save[0]);
  342. __insn_mtspr(SPR_SYSTEM_SAVE_0_1, t->system_save[1]);
  343. __insn_mtspr(SPR_SYSTEM_SAVE_0_2, t->system_save[2]);
  344. __insn_mtspr(SPR_SYSTEM_SAVE_0_3, t->system_save[3]);
  345. __insn_mtspr(SPR_INTCTRL_0_STATUS, t->intctrl_0);
  346. #if CHIP_HAS_PROC_STATUS_SPR()
  347. __insn_mtspr(SPR_PROC_STATUS, t->proc_status);
  348. #endif
  349. #if !CHIP_HAS_FIXED_INTVEC_BASE()
  350. __insn_mtspr(SPR_INTERRUPT_VECTOR_BASE_0, t->interrupt_vector_base);
  351. #endif
  352. #if CHIP_HAS_TILE_RTF_HWM()
  353. __insn_mtspr(SPR_TILE_RTF_HWM, t->tile_rtf_hwm);
  354. #endif
  355. #if CHIP_HAS_DSTREAM_PF()
  356. __insn_mtspr(SPR_DSTREAM_PF, t->dstream_pf);
  357. #endif
  358. }
  359. void _prepare_arch_switch(struct task_struct *next)
  360. {
  361. #if CHIP_HAS_SN_PROC()
  362. int snctl;
  363. #endif
  364. #if CHIP_HAS_TILE_DMA()
  365. struct tile_dma_state *dma = &current->thread.tile_dma_state;
  366. if (dma->enabled)
  367. save_tile_dma_state(dma);
  368. #endif
  369. #if CHIP_HAS_SN_PROC()
  370. /*
  371. * Suspend the static network processor if it was running.
  372. * We do not suspend the fabric itself, just like we don't
  373. * try to suspend the UDN.
  374. */
  375. snctl = __insn_mfspr(SPR_SNCTL);
  376. current->thread.sn_proc_running =
  377. (snctl & SPR_SNCTL__FRZPROC_MASK) == 0;
  378. if (current->thread.sn_proc_running)
  379. __insn_mtspr(SPR_SNCTL, snctl | SPR_SNCTL__FRZPROC_MASK);
  380. #endif
  381. }
  382. struct task_struct *__sched _switch_to(struct task_struct *prev,
  383. struct task_struct *next)
  384. {
  385. /* DMA state is already saved; save off other arch state. */
  386. save_arch_state(&prev->thread);
  387. #if CHIP_HAS_TILE_DMA()
  388. /*
  389. * Restore DMA in new task if desired.
  390. * Note that it is only safe to restart here since interrupts
  391. * are disabled, so we can't take any DMATLB miss or access
  392. * interrupts before we have finished switching stacks.
  393. */
  394. if (next->thread.tile_dma_state.enabled) {
  395. restore_tile_dma_state(&next->thread);
  396. grant_dma_mpls();
  397. } else {
  398. restrict_dma_mpls();
  399. }
  400. #endif
  401. /* Restore other arch state. */
  402. restore_arch_state(&next->thread);
  403. #if CHIP_HAS_SN_PROC()
  404. /*
  405. * Restart static network processor in the new process
  406. * if it was running before.
  407. */
  408. if (next->thread.sn_proc_running) {
  409. int snctl = __insn_mfspr(SPR_SNCTL);
  410. __insn_mtspr(SPR_SNCTL, snctl & ~SPR_SNCTL__FRZPROC_MASK);
  411. }
  412. #endif
  413. #ifdef CONFIG_HARDWALL
  414. /* Enable or disable access to the network registers appropriately. */
  415. hardwall_switch_tasks(prev, next);
  416. #endif
  417. /*
  418. * Switch kernel SP, PC, and callee-saved registers.
  419. * In the context of the new task, return the old task pointer
  420. * (i.e. the task that actually called __switch_to).
  421. * Pass the value to use for SYSTEM_SAVE_K_0 when we reset our sp.
  422. */
  423. return __switch_to(prev, next, next_current_ksp0(next));
  424. }
  425. /*
  426. * This routine is called on return from interrupt if any of the
  427. * TIF_WORK_MASK flags are set in thread_info->flags. It is
  428. * entered with interrupts disabled so we don't miss an event
  429. * that modified the thread_info flags. If any flag is set, we
  430. * handle it and return, and the calling assembly code will
  431. * re-disable interrupts, reload the thread flags, and call back
  432. * if more flags need to be handled.
  433. *
  434. * We return whether we need to check the thread_info flags again
  435. * or not. Note that we don't clear TIF_SINGLESTEP here, so it's
  436. * important that it be tested last, and then claim that we don't
  437. * need to recheck the flags.
  438. */
  439. int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
  440. {
  441. /* If we enter in kernel mode, do nothing and exit the caller loop. */
  442. if (!user_mode(regs))
  443. return 0;
  444. /* Enable interrupts; they are disabled again on return to caller. */
  445. local_irq_enable();
  446. if (thread_info_flags & _TIF_NEED_RESCHED) {
  447. schedule();
  448. return 1;
  449. }
  450. #if CHIP_HAS_TILE_DMA() || CHIP_HAS_SN_PROC()
  451. if (thread_info_flags & _TIF_ASYNC_TLB) {
  452. do_async_page_fault(regs);
  453. return 1;
  454. }
  455. #endif
  456. if (thread_info_flags & _TIF_SIGPENDING) {
  457. do_signal(regs);
  458. return 1;
  459. }
  460. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  461. clear_thread_flag(TIF_NOTIFY_RESUME);
  462. tracehook_notify_resume(regs);
  463. return 1;
  464. }
  465. if (thread_info_flags & _TIF_SINGLESTEP) {
  466. single_step_once(regs);
  467. return 0;
  468. }
  469. panic("work_pending: bad flags %#x\n", thread_info_flags);
  470. }
  471. unsigned long get_wchan(struct task_struct *p)
  472. {
  473. struct KBacktraceIterator kbt;
  474. if (!p || p == current || p->state == TASK_RUNNING)
  475. return 0;
  476. for (KBacktraceIterator_init(&kbt, p, NULL);
  477. !KBacktraceIterator_end(&kbt);
  478. KBacktraceIterator_next(&kbt)) {
  479. if (!in_sched_functions(kbt.it.pc))
  480. return kbt.it.pc;
  481. }
  482. return 0;
  483. }
  484. /* Flush thread state. */
  485. void flush_thread(void)
  486. {
  487. /* Nothing */
  488. }
  489. /*
  490. * Free current thread data structures etc..
  491. */
  492. void exit_thread(void)
  493. {
  494. #ifdef CONFIG_HARDWALL
  495. /*
  496. * Remove the task from the list of tasks that are associated
  497. * with any live hardwalls. (If the task that is exiting held
  498. * the last reference to a hardwall fd, it would already have
  499. * been released and deactivated at this point.)
  500. */
  501. hardwall_deactivate_all(current);
  502. #endif
  503. }
  504. void show_regs(struct pt_regs *regs)
  505. {
  506. struct task_struct *tsk = validate_current();
  507. int i;
  508. pr_err("\n");
  509. show_regs_print_info(KERN_ERR);
  510. #ifdef __tilegx__
  511. for (i = 0; i < 51; i += 3)
  512. pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
  513. i, regs->regs[i], i+1, regs->regs[i+1],
  514. i+2, regs->regs[i+2]);
  515. pr_err(" r51: "REGFMT" r52: "REGFMT" tp : "REGFMT"\n",
  516. regs->regs[51], regs->regs[52], regs->tp);
  517. pr_err(" sp : "REGFMT" lr : "REGFMT"\n", regs->sp, regs->lr);
  518. #else
  519. for (i = 0; i < 52; i += 4)
  520. pr_err(" r%-2d: "REGFMT" r%-2d: "REGFMT
  521. " r%-2d: "REGFMT" r%-2d: "REGFMT"\n",
  522. i, regs->regs[i], i+1, regs->regs[i+1],
  523. i+2, regs->regs[i+2], i+3, regs->regs[i+3]);
  524. pr_err(" r52: "REGFMT" tp : "REGFMT" sp : "REGFMT" lr : "REGFMT"\n",
  525. regs->regs[52], regs->tp, regs->sp, regs->lr);
  526. #endif
  527. pr_err(" pc : "REGFMT" ex1: %ld faultnum: %ld\n",
  528. regs->pc, regs->ex1, regs->faultnum);
  529. dump_stack_regs(regs);
  530. }