From: Richard Kuo <rkuo@codeaurora.org>
To: linux-kernel@vger.kernel.org, linux-hexagon@vger.kernel.org
Subject: [patch v2 15/35] Hexagon: Add init_task and process functions
Date: Tue, 30 Aug 2011 14:07:44 -0500 [thread overview]
Message-ID: <20110830190801.159310885@codeaurora.org> (raw)
In-Reply-To: 20110830190729.923334292@codeaurora.org
[-- Attachment #1: init-task.diff --]
[-- Type: text/plain, Size: 10409 bytes --]
Fixed potential race-to-sleep condition in cpu_idle(). I hope.
If called with interrupts disabled, our __vmwait() actually just returns
without servicing it. Let me know if there's any other condition that
I've missed...
Signed-off-by: Richard Kuo <rkuo@codeaurora.org>
---
arch/hexagon/kernel/init_task.c | 54 +++++++
arch/hexagon/kernel/process.c | 278 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 332 insertions(+)
Index: linux-hexagon-kernel/arch/hexagon/kernel/init_task.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-hexagon-kernel/arch/hexagon/kernel/init_task.c 2011-08-24 18:45:48.203877165 -0500
@@ -0,0 +1,54 @@
+/*
+ * Init task definition
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/init_task.h>
+#include <linux/fs.h>
+#include <linux/mqueue.h>
+#include <asm/thread_info.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+
+static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
+static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
+
+/*
+ * Initial thread structure.
+ *
+ * We need to make sure that this is 8192-byte aligned due to the
+ * way process stacks are handled. This is done by making sure
+ * the linker maps this in the .text segment right after head.S,
+ * and making head.S ensure the proper alignment.
+ */
+union thread_union init_thread_union
+ __attribute__((__section__(".data.init_task"),
+ __aligned__(THREAD_SIZE))) = {
+ INIT_THREAD_INFO(init_task)
+ };
+
+/*
+ * Initial task structure.
+ *
+ * All other task structs will be allocated on slabs in fork.c
+ */
+struct task_struct init_task = INIT_TASK(init_task);
+EXPORT_SYMBOL(init_task);
Index: linux-hexagon-kernel/arch/hexagon/kernel/process.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ linux-hexagon-kernel/arch/hexagon/kernel/process.c 2011-08-24 18:45:48.203877165 -0500
@@ -0,0 +1,278 @@
+/*
+ * Process creation support for Hexagon
+ *
+ * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/tick.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+
+/*
+ * Kernel thread creation. The desired kernel function is "wrapped"
+ * in the kernel_thread_helper function, which does cleanup
+ * afterwards.
+ */
+static void __noreturn kernel_thread_helper(void *arg, int (*fn)(void *))
+{
+ do_exit(fn(arg));
+}
+
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+ struct pt_regs regs;
+
+ memset(®s, 0, sizeof(regs));
+ /*
+ * Yes, we're exploting illicit knowledge of the ABI here.
+ */
+ regs.r00 = (unsigned long) arg;
+ regs.r01 = (unsigned long) fn;
+ pt_set_elr(®s, (unsigned long)kernel_thread_helper);
+ pt_set_kmode(®s);
+
+ return do_fork(flags|CLONE_VM|CLONE_UNTRACED, 0, ®s, 0, NULL, NULL);
+}
+EXPORT_SYMBOL(kernel_thread);
+
+/*
+ * Program thread launch. Often defined as a macro in processor.h,
+ * but we're shooting for a small footprint and it's not an inner-loop
+ * performance-critical operation.
+ *
+ * The Hexagon ABI specifies that R28 is zero'ed before program launch,
+ * so that gets automatically done here. If we ever stop doing that here,
+ * we'll probably want to define the ELF_PLAT_INIT macro.
+ */
+void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
+{
+ /* Set to run with user-mode data segmentation */
+ set_fs(USER_DS);
+ /* We want to zero all data-containing registers. Is this overkill? */
+ memset(regs, 0, sizeof(*regs));
+ /* We might want to also zero all Processor registers here */
+ pt_set_usermode(regs);
+ pt_set_elr(regs, pc);
+ pt_set_rte_sp(regs, sp);
+}
+
+/*
+ * Spin, or better still, do a hardware or VM wait instruction
+ * If hardware or VM offer wait termination even though interrupts
+ * are disabled.
+ */
+static void default_idle(void)
+{
+ __vmwait();
+}
+
+void (*idle_sleep)(void) = default_idle;
+
+void cpu_idle(void)
+{
+ while (1) {
+ tick_nohz_stop_sched_tick(1);
+ local_irq_disable();
+ while (!need_resched()) {
+ idle_sleep();
+ /* interrupts wake us up, but aren't serviced */
+ local_irq_enable(); /* service interrupt */
+ local_irq_disable();
+ }
+ tick_nohz_restart_sched_tick();
+ schedule();
+ }
+}
+
+/*
+ * Return saved PC of a blocked thread
+ */
+unsigned long thread_saved_pc(struct task_struct *tsk)
+{
+ return 0;
+}
+
+/*
+ * Copy architecture-specific thread state
+ */
+int copy_thread(unsigned long clone_flags, unsigned long usp,
+ unsigned long unused, struct task_struct *p,
+ struct pt_regs *regs)
+{
+ struct thread_info *ti = task_thread_info(p);
+ struct hexagon_switch_stack *ss;
+ struct pt_regs *childregs;
+ asmlinkage void ret_from_fork(void);
+
+ childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
+ sizeof(*childregs));
+
+ memcpy(childregs, regs, sizeof(*childregs));
+ ti->regs = childregs;
+
+ /*
+ * Establish kernel stack pointer and initial PC for new thread
+ */
+ ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
+ sizeof(*ss));
+ ss->lr = (unsigned long)ret_from_fork;
+ p->thread.switch_sp = ss;
+
+ /* If User mode thread, set pt_reg stack pointer as per parameter */
+ if (user_mode(childregs)) {
+ pt_set_rte_sp(childregs, usp);
+
+ /* Child sees zero return value */
+ childregs->r00 = 0;
+
+ /*
+ * The clone syscall has the C signature:
+ * int [r0] clone(int flags [r0],
+ * void *child_frame [r1],
+ * void *parent_tid [r2],
+ * void *child_tid [r3],
+ * void *thread_control_block [r4]);
+ * ugp is used to provide TLS support.
+ */
+ if (clone_flags & CLONE_SETTLS)
+ childregs->ugp = childregs->r04;
+
+ /*
+ * Parent sees new pid -- not necessary, not even possible at
+ * this point in the fork process
+ * Might also want to set things like ti->addr_limit
+ */
+ } else {
+ /*
+ * If kernel thread, resume stack is kernel stack base.
+ * Note that this is pointer arithmetic on pt_regs *
+ */
+ pt_set_rte_sp(childregs, (unsigned long)(childregs + 1));
+ /*
+ * We need the current thread_info fast path pointer
+ * set up in pt_regs. The register to be used is
+ * parametric for assembler code, but the mechanism
+ * doesn't drop neatly into C. Needs to be fixed.
+ */
+ childregs->THREADINFO_REG = (unsigned long) ti;
+ }
+
+ /*
+ * thread_info pointer is pulled out of task_struct "stack"
+ * field on switch_to.
+ */
+ p->stack = (void *)ti;
+
+ return 0;
+}
+
+/*
+ * Release any architecture-specific resources locked by thread
+ */
+void release_thread(struct task_struct *dead_task)
+{
+}
+
+/*
+ * Free any architecture-specific thread data structures, etc.
+ */
+void exit_thread(void)
+{
+}
+
+/*
+ * Some archs flush debug and FPU info here
+ */
+void flush_thread(void)
+{
+}
+
+/*
+ * The "wait channel" terminology is archaic, but what we want
+ * is an identification of the point at which the scheduler
+ * was invoked by a blocked thread.
+ */
+unsigned long get_wchan(struct task_struct *p)
+{
+ unsigned long fp, pc;
+ unsigned long stack_page;
+ int count = 0;
+ if (!p || p == current || p->state == TASK_RUNNING)
+ return 0;
+
+ stack_page = (unsigned long)task_stack_page(p);
+ fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
+ do {
+ if (fp < (stack_page + sizeof(struct thread_info)) ||
+ fp >= (THREAD_SIZE - 8 + stack_page))
+ return 0;
+ pc = ((unsigned long *)fp)[1];
+ if (!in_sched_functions(pc))
+ return pc;
+ fp = *(unsigned long *) fp;
+ } while (count++ < 16);
+
+ return 0;
+}
+
+/*
+ * Borrowed from PowerPC -- basically allow smaller kernel stacks if we
+ * go crazy with the page sizes.
+ */
+#if THREAD_SHIFT < PAGE_SHIFT
+
+static struct kmem_cache *thread_info_cache;
+
+struct thread_info *alloc_thread_info_node(struct task_struct *tsk, int node)
+{
+ struct thread_info *ti;
+
+ ti = kmem_cache_alloc_node(thread_info_cache, GFP_KERNEL, node);
+ if (unlikely(ti == NULL))
+ return NULL;
+#ifdef CONFIG_DEBUG_STACK_USAGE
+ memset(ti, 0, THREAD_SIZE);
+#endif
+ return ti;
+}
+
+void free_thread_info(struct thread_info *ti)
+{
+ kmem_cache_free(thread_info_cache, ti);
+}
+
+/* Weak symbol; called by init/main.c */
+
+void thread_info_cache_init(void)
+{
+ thread_info_cache = kmem_cache_create("thread_info", THREAD_SIZE,
+ THREAD_SIZE, 0, NULL);
+ BUG_ON(thread_info_cache == NULL);
+}
+
+#endif /* THREAD_SHIFT < PAGE_SHIFT */
+
+/*
+ * Required placeholder.
+ */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
+{
+ return 0;
+}
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2011-08-30 19:07 UTC|newest]
Thread overview: 82+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 19:07 [patch v2 00/35] Hexagon: Add support for Qualcomm Hexagon architecture Richard Kuo
2011-08-30 19:07 ` [patch v2 01/35] Hexagon: Add generic headers Richard Kuo
2011-08-31 13:24 ` Arnd Bergmann
2011-08-31 19:51 ` David Brown
2011-08-31 20:00 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 02/35] Hexagon: Core arch-specific header files Richard Kuo
2011-08-31 13:25 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 03/35] Hexagon: Add bitops support Richard Kuo
2011-08-31 13:26 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 04/35] Hexagon: Add atomic ops support Richard Kuo
2011-08-31 13:26 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 05/35] Hexagon: Add syscalls Richard Kuo
2011-08-31 13:34 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 06/35] Hexagon: Add processor and system headers Richard Kuo
2011-08-31 13:35 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 07/35] Hexagon: Add threadinfo Richard Kuo
2011-08-31 13:36 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 08/35] Hexagon: Add delay functions Richard Kuo
2011-08-31 13:39 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 09/35] Hexagon: Add checksum functions Richard Kuo
2011-08-30 19:34 ` Joe Perches
2011-08-30 19:52 ` Sam Ravnborg
2011-08-31 14:49 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 10/35] Hexagon: Add memcpy and memset accelerated functions Richard Kuo
2011-08-31 13:40 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 11/35] Hexagon: Add hypervisor interface Richard Kuo
2011-08-31 13:41 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 12/35] Hexagon: Export ksyms defined in assembly files Richard Kuo
2011-08-31 13:41 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 13/35] Hexagon: Support dynamic module loading Richard Kuo
2011-08-31 13:41 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 14/35] Hexagon: Add signal functions Richard Kuo
2011-08-31 13:42 ` Arnd Bergmann
2011-08-30 19:07 ` Richard Kuo [this message]
2011-08-31 13:45 ` [patch v2 15/35] Hexagon: Add init_task and process functions Arnd Bergmann
2011-08-30 19:07 ` [patch v2 16/35] Hexagon: Add startup code Richard Kuo
2011-08-31 13:46 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 17/35] Hexagon: Add interrupts Richard Kuo
2011-08-31 13:50 ` Arnd Bergmann
2011-08-31 16:16 ` Linas Vepstas (Code Aurora)
2011-08-30 19:07 ` [patch v2 18/35] Hexagon: Add time and timer functions Richard Kuo
2011-08-31 14:04 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 19/35] Hexagon: Add ptrace support Richard Kuo
2011-08-31 14:07 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 20/35] Hexagon: Provide basic debugging and system trap support Richard Kuo
2011-08-31 14:08 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 21/35] Hexagon: Add SMP support Richard Kuo
2011-08-30 19:30 ` Joe Perches
2011-08-30 20:50 ` Richard Kuo
2011-08-31 15:00 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 22/35] Hexagon: Add locking types and functions Richard Kuo
2011-08-31 14:09 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 23/35] Hexagon: Add user access functions Richard Kuo
2011-08-31 14:10 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 24/35] Hexagon: Provide basic implementation and/or stubs for I/O routines Richard Kuo
2011-08-31 14:28 ` Arnd Bergmann
2011-08-31 14:47 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 25/35] Hexagon: Implement basic cache-flush support Richard Kuo
2011-08-31 14:49 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 26/35] Hexagon: Implement basic TLB management routines for Hexagon Richard Kuo
2011-08-31 14:49 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 27/35] Hexagon: Provide DMA implementation Richard Kuo
2011-08-31 14:51 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 28/35] Hexagon: Add ioremap support Richard Kuo
2011-08-31 14:53 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 29/35] Hexagon: Add page table header files & etc Richard Kuo
2011-08-31 14:57 ` Arnd Bergmann
2011-08-30 19:07 ` [patch v2 30/35] Hexagon: Add page-fault support Richard Kuo
2011-08-31 14:58 ` Arnd Bergmann
2011-08-30 19:08 ` [patch v2 31/35] Hexagon: kgdb support files Richard Kuo
2011-08-31 14:58 ` Arnd Bergmann
2011-08-30 19:08 ` [patch v2 32/35] Hexagon: Comet platform support Richard Kuo
2011-08-31 15:00 ` Arnd Bergmann
2011-08-30 19:08 ` [patch v2 33/35] Hexagon: Add configuration and makefiles for the Hexagon architecture Richard Kuo
2011-08-31 14:59 ` Arnd Bergmann
2011-08-30 19:08 ` [patch v2 34/35] Hexagon: Add basic stacktrace functionality for " Richard Kuo
2011-08-31 14:59 ` Arnd Bergmann
2011-08-30 19:08 ` [patch v2 35/35] Hexagon: Add self to MAINTAINERS Richard Kuo
2011-08-31 14:59 ` Arnd Bergmann
2011-08-30 20:18 ` [patch v2 00/35] Hexagon: Add support for Qualcomm Hexagon architecture Pekka Enberg
2011-08-30 20:48 ` Linas Vepstas (Code Aurora)
2011-08-31 15:08 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110830190801.159310885@codeaurora.org \
--to=rkuo@codeaurora.org \
--cc=linux-hexagon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).