Skip to content

Commit bf90e1e

Browse files
committed
ARC: Process-creation/scheduling/idle-loop
Signed-off-by: Vineet Gupta <vgupta@synopsys.com> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Thomas Gleixner <tglx@linutronix.de>
1 parent 4adeefe commit bf90e1e

10 files changed

Lines changed: 484 additions & 8 deletions

File tree

‎arch/arc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ config ARC
1717
select GENERIC_FIND_FIRST_BIT
1818
# for now, we don't need GENERIC_IRQ_PROBE, CONFIG_GENERIC_IRQ_CHIP
1919
select GENERIC_IRQ_SHOW
20+
select GENERIC_KERNEL_EXECVE
21+
select GENERIC_KERNEL_THREAD
2022
select GENERIC_PENDING_IRQ if SMP
2123
select GENERIC_SMP_IDLE_THREAD
2224
select HAVE_GENERIC_HARDIRQS

‎arch/arc/include/asm/arcregs.h‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@
4747
#define AUX_ITRIGGER 0x40d
4848
#define AUX_IPULSE 0x415
4949

50+
/*
51+
* Floating Pt Registers
52+
* Status regs are read-only (build-time) so need not be saved/restored
53+
*/
54+
#define ARC_AUX_FP_STAT 0x300
55+
#define ARC_AUX_DPFP_1L 0x301
56+
#define ARC_AUX_DPFP_1H 0x302
57+
#define ARC_AUX_DPFP_2L 0x303
58+
#define ARC_AUX_DPFP_2H 0x304
59+
#define ARC_AUX_DPFP_STAT 0x305
60+
5061
#ifndef __ASSEMBLY__
5162

5263
/*
@@ -110,6 +121,15 @@
110121

111122
#endif
112123

124+
#ifdef CONFIG_ARC_FPU_SAVE_RESTORE
125+
/* These DPFP regs need to be saved/restored across ctx-sw */
126+
struct arc_fpu {
127+
struct {
128+
unsigned int l, h;
129+
} aux_dpfp[2];
130+
};
131+
#endif
132+
113133
#endif /* __ASEMBLY__ */
114134

115135
#endif /* __KERNEL__ */

‎arch/arc/include/asm/processor.h‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ struct thread_struct {
2929
unsigned long callee_reg; /* pointer to callee regs */
3030
unsigned long fault_address; /* dbls as brkpt holder as well */
3131
unsigned long cause_code; /* Exception Cause Code (ECR) */
32+
#ifdef CONFIG_ARC_FPU_SAVE_RESTORE
33+
struct arc_fpu fpu;
34+
#endif
3235
};
3336

3437
#define INIT_THREAD { \
@@ -54,12 +57,6 @@ unsigned long thread_saved_pc(struct task_struct *t);
5457

5558
#define cpu_relax() do { } while (0)
5659

57-
/*
58-
* Create a new kernel thread
59-
*/
60-
61-
extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
62-
6360
#define copy_segments(tsk, mm) do { } while (0)
6461
#define release_segments(mm) do { } while (0)
6562

‎arch/arc/include/asm/ptrace.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ struct callee_regs {
9191
#define in_syscall(regs) (((regs->orig_r8) >= 0 && \
9292
(regs->orig_r8 <= NR_syscalls)) ? 1 : 0)
9393

94+
#define current_pt_regs() \
95+
({ \
96+
/* open-coded current_thread_info() */ \
97+
register unsigned long sp asm ("sp"); \
98+
unsigned long pg_start = (sp & ~(THREAD_SIZE - 1)); \
99+
(struct pt_regs *)(pg_start + THREAD_SIZE - 4) - 1; \
100+
})
101+
94102
#endif /* !__ASSEMBLY__ */
95103

96104
#endif /* __KERNEL__ */

‎arch/arc/include/asm/switch_to.h‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#ifndef _ASM_ARC_SWITCH_TO_H
10+
#define _ASM_ARC_SWITCH_TO_H
11+
12+
#ifndef __ASSEMBLY__
13+
14+
#include <linux/sched.h>
15+
16+
#ifdef CONFIG_ARC_FPU_SAVE_RESTORE
17+
18+
extern void fpu_save_restore(struct task_struct *p, struct task_struct *n);
19+
#define ARC_FPU_PREV(p, n) fpu_save_restore(p, n)
20+
#define ARC_FPU_NEXT(t)
21+
22+
#else
23+
24+
#define ARC_FPU_PREV(p, n)
25+
#define ARC_FPU_NEXT(n)
26+
27+
#endif /* !CONFIG_ARC_FPU_SAVE_RESTORE */
28+
29+
struct task_struct *__switch_to(struct task_struct *p, struct task_struct *n);
30+
31+
#define switch_to(prev, next, last) \
32+
do { \
33+
ARC_FPU_PREV(prev, next); \
34+
last = __switch_to(prev, next);\
35+
ARC_FPU_NEXT(next); \
36+
mb(); \
37+
} while (0)
38+
39+
#endif
40+
41+
#endif

‎arch/arc/kernel/ctx_sw.c‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* Vineetg: Aug 2009
9+
* -"C" version of lowest level context switch asm macro called by schedular
10+
* gcc doesn't generate the dward CFI info for hand written asm, hence can't
11+
* backtrace out of it (e.g. tasks sleeping in kernel).
12+
* So we cheat a bit by writing almost similar code in inline-asm.
13+
* -This is a hacky way of doing things, but there is no other simple way.
14+
* I don't want/intend to extend unwinding code to understand raw asm
15+
*/
16+
17+
#include <asm/asm-offsets.h>
18+
#include <linux/sched.h>
19+
20+
struct task_struct *__sched
21+
__switch_to(struct task_struct *prev_task, struct task_struct *next_task)
22+
{
23+
unsigned int tmp;
24+
unsigned int prev = (unsigned int)prev_task;
25+
unsigned int next = (unsigned int)next_task;
26+
int num_words_to_skip = 1;
27+
28+
__asm__ __volatile__(
29+
/* FP/BLINK save generated by gcc (standard function prologue */
30+
"st.a r13, [sp, -4] \n\t"
31+
"st.a r14, [sp, -4] \n\t"
32+
"st.a r15, [sp, -4] \n\t"
33+
"st.a r16, [sp, -4] \n\t"
34+
"st.a r17, [sp, -4] \n\t"
35+
"st.a r18, [sp, -4] \n\t"
36+
"st.a r19, [sp, -4] \n\t"
37+
"st.a r20, [sp, -4] \n\t"
38+
"st.a r21, [sp, -4] \n\t"
39+
"st.a r22, [sp, -4] \n\t"
40+
"st.a r23, [sp, -4] \n\t"
41+
"st.a r24, [sp, -4] \n\t"
42+
"st.a r25, [sp, -4] \n\t"
43+
"sub sp, sp, %4 \n\t" /* create gutter at top */
44+
45+
/* set ksp of outgoing task in tsk->thread.ksp */
46+
"st.as sp, [%3, %1] \n\t"
47+
48+
"sync \n\t"
49+
50+
/*
51+
* setup _current_task with incoming tsk.
52+
* optionally, set r25 to that as well
53+
* For SMP extra work to get to &_current_task[cpu]
54+
* (open coded SET_CURR_TASK_ON_CPU)
55+
*/
56+
"st %2, [@_current_task] \n\t"
57+
58+
/* get ksp of incoming task from tsk->thread.ksp */
59+
"ld.as sp, [%2, %1] \n\t"
60+
61+
/* start loading it's CALLEE reg file */
62+
63+
"add sp, sp, %4 \n\t" /* skip gutter at top */
64+
65+
"ld.ab r25, [sp, 4] \n\t"
66+
"ld.ab r24, [sp, 4] \n\t"
67+
"ld.ab r23, [sp, 4] \n\t"
68+
"ld.ab r22, [sp, 4] \n\t"
69+
"ld.ab r21, [sp, 4] \n\t"
70+
"ld.ab r20, [sp, 4] \n\t"
71+
"ld.ab r19, [sp, 4] \n\t"
72+
"ld.ab r18, [sp, 4] \n\t"
73+
"ld.ab r17, [sp, 4] \n\t"
74+
"ld.ab r16, [sp, 4] \n\t"
75+
"ld.ab r15, [sp, 4] \n\t"
76+
"ld.ab r14, [sp, 4] \n\t"
77+
"ld.ab r13, [sp, 4] \n\t"
78+
79+
/* last (ret value) = prev : although for ARC it mov r0, r0 */
80+
"mov %0, %3 \n\t"
81+
82+
/* FP/BLINK restore generated by gcc (standard func epilogue */
83+
84+
: "=r"(tmp)
85+
: "n"((TASK_THREAD + THREAD_KSP) / 4), "r"(next), "r"(prev),
86+
"n"(num_words_to_skip * 4)
87+
: "blink"
88+
);
89+
90+
return (struct task_struct *)tmp;
91+
}

‎arch/arc/kernel/ctx_sw_asm.S‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* Vineetg: Aug 2009
9+
* -Moved core context switch macro out of entry.S into this file.
10+
* -This is the more "natural" hand written assembler
11+
*/
12+
13+
#include <asm/entry.h> /* For the SAVE_* macros */
14+
#include <asm/asm-offsets.h>
15+
#include <asm/linkage.h>
16+
17+
;################### Low Level Context Switch ##########################
18+
19+
.section .sched.text,"ax",@progbits
20+
.align 4
21+
.global __switch_to
22+
.type __switch_to, @function
23+
__switch_to:
24+
25+
/* Save regs on kernel mode stack of task */
26+
st.a blink, [sp, -4]
27+
st.a fp, [sp, -4]
28+
SAVE_CALLEE_SAVED_KERNEL
29+
30+
/* Save the now KSP in task->thread.ksp */
31+
st.as sp, [r0, (TASK_THREAD + THREAD_KSP)/4]
32+
33+
/*
34+
* Return last task in r0 (return reg)
35+
* On ARC, Return reg = First Arg reg = r0.
36+
* Since we already have last task in r0,
37+
* don't need to do anything special to return it
38+
*/
39+
40+
/* hardware memory barrier */
41+
sync
42+
43+
/*
44+
* switch to new task, contained in r1
45+
* Temp reg r3 is required to get the ptr to store val
46+
*/
47+
SET_CURR_TASK_ON_CPU r1, r3
48+
49+
/* reload SP with kernel mode stack pointer in task->thread.ksp */
50+
ld.as sp, [r1, (TASK_THREAD + THREAD_KSP)/4]
51+
52+
/* restore the registers */
53+
RESTORE_CALLEE_SAVED_KERNEL
54+
ld.ab fp, [sp, 4]
55+
ld.ab blink, [sp, 4]
56+
j [blink]
57+
58+
ARC_EXIT __switch_to

‎arch/arc/kernel/entry.S‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,19 @@ ARC_ENTRY ret_from_fork
566566
; when the forked child comes here from the __switch_to function
567567
; r0 has the last task pointer.
568568
; put last task in scheduler queue
569-
bl @schedule_tail
570-
b @ret_from_exception
569+
bl @schedule_tail
570+
571+
; If kernel thread, jump to it's entry-point
572+
ld r9, [sp, PT_status32]
573+
brne r9, 0, 1f
574+
575+
jl.d [r14]
576+
mov r0, r13 ; arg to payload
577+
578+
1:
579+
; special case of kernel_thread entry point returning back due to
580+
; kernel_execve() - pretend return from syscall to ret to userland
581+
b ret_from_exception
571582
ARC_EXIT ret_from_fork
572583

573584
;################### Special Sys Call Wrappers ##########################

‎arch/arc/kernel/fpu.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* fpu.c - save/restore of Floating Point Unit Registers on task switch
3+
*
4+
* Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#include <linux/sched.h>
12+
#include <asm/switch_to.h>
13+
14+
/*
15+
* To save/restore FPU regs, simplest scheme would use LR/SR insns.
16+
* However since SR serializes the pipeline, an alternate "hack" can be used
17+
* which uses the FPU Exchange insn (DEXCL) to r/w FPU regs.
18+
*
19+
* Store to 64bit dpfp1 reg from a pair of core regs:
20+
* dexcl1 0, r1, r0 ; where r1:r0 is the 64 bit val
21+
*
22+
* Read from dpfp1 into pair of core regs (w/o clobbering dpfp1)
23+
* mov_s r3, 0
24+
* daddh11 r1, r3, r3 ; get "hi" into r1 (dpfp1 unchanged)
25+
* dexcl1 r0, r1, r3 ; get "low" into r0 (dpfp1 low clobbered)
26+
* dexcl1 0, r1, r0 ; restore dpfp1 to orig value
27+
*
28+
* However we can tweak the read, so that read-out of outgoing task's FPU regs
29+
* and write of incoming task's regs happen in one shot. So all the work is
30+
* done before context switch
31+
*/
32+
33+
void fpu_save_restore(struct task_struct *prev, struct task_struct *next)
34+
{
35+
unsigned int *saveto = &prev->thread.fpu.aux_dpfp[0].l;
36+
unsigned int *readfrom = &next->thread.fpu.aux_dpfp[0].l;
37+
38+
const unsigned int zero = 0;
39+
40+
__asm__ __volatile__(
41+
"daddh11 %0, %2, %2\n"
42+
"dexcl1 %1, %3, %4\n"
43+
: "=&r" (*(saveto + 1)), /* early clobber must here */
44+
"=&r" (*(saveto))
45+
: "r" (zero), "r" (*(readfrom + 1)), "r" (*(readfrom))
46+
);
47+
48+
__asm__ __volatile__(
49+
"daddh22 %0, %2, %2\n"
50+
"dexcl2 %1, %3, %4\n"
51+
: "=&r"(*(saveto + 3)), /* early clobber must here */
52+
"=&r"(*(saveto + 2))
53+
: "r" (zero), "r" (*(readfrom + 3)), "r" (*(readfrom + 2))
54+
);
55+
}

0 commit comments

Comments
 (0)