Switch master cpu after gdb thread command for SMP (v2)
PATCH 1/1 Switch master cpu after gdb thread command for SMP (v2)
In blackfin SMP architecture, different core has its own L1 SRAM and MMR memory, which code running on the other core can't access. In current kgdb impelemntation, cpus are represented by thread with minus prefix.
If user run thread command in gdb to switch to the thread of the other cpu, kgdb should:
1. send IPI signal to master cpu
2. release the specific passive cpu waiting in IPI handler
3. exit kgdb exception loop on master cpu and trap into kgdb wait in IPI handler
4. trap the released passive cpu into kgdb exception in IPI handler
This patch is tested on bf561-ezkit board with SMP enabled.
--- include/linux/kgdb.h | 14 +++++++++++ kernel/kgdb.c | 64 +++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 9 deletions(-)
include/linux/kgdb.h +14 -0
@@ -107,6 +107,7 @@ struct kgdb_bkpt {#endif #define KGDB_HW_BREAKPOINT 1 +#define KGDB_THR_PROC_SWAP 2/* * Functions each KGDB-supporting architecture must provide:
@@ -203,6 +204,19 @@ kgdb_arch_handle_exception(int vector, int signo, int err_code,*/ extern void kgdb_roundup_cpus (unsigned long flags); +/** +* kgdb_roundup_cpu - Get spcific CPU into a holding pattern +* @cpu: Specific cpu id +* @flags: Current IRQ state +* +* On SMP systems, we need to switch cpu from current active one to +* the other passive one. This get current active CPU into a known state +* in kgdb_wait(). +* +* On non-SMP systems, this is not called. +*/ +extern void kgdb_roundup_cpu (int cpu,unsigned long flags); +/* Optional functions. */ extern int kgdb_validate_break_address (unsigned long addr);extern int kgdb_arch_set_breakpoint (unsigned long addr,char *saved_instr);
kernel/kgdb.c +55 -9
159 lines not on this page · raw message
Signature · 1 line
1.6.0
Jason Wessel
maintainerRe: [PATCH] [kgdb] Switch master cpu after gdb thread command for SMP(v2)
Quoted 2 lines · sonic zhang
In blackfin SMP architecture, different core has its own L1 SRAM and MMR memory, which code running on the other core can't access. In current
kgdb
Quoted 7 lines
impelemntation, cpus are represented by thread with minus prefix.
If user run thread command in gdb to switch to the thread of the other cpu, kgdb should:
1. send IPI signal to master cpu
2. release the specific passive cpu waiting in IPI handler
3. exit kgdb exception loop on master cpu and trap into kgdb wait in
IPI handler
Quoted 4 lines
4. trap the released passive cpu into kgdb exception in IPI handler
This patch is tested on bf561-ezkit board with SMP enabled.
It does look better this time around, but the patch does not apply to the kgdb dev branch.
Hunk #10 FAILED at 1502.
Hunk #11 FAILED at 1518.
Hunk #12 FAILED at 1537.
Hunk #13 FAILED at 1550.
Hunk #14 succeeded at 1584 (offset -12 lines).
4 out of 14 hunks FAILED -- rejects in file kernel/kgdb.c
Quoted 5 lines
Signed-off-by Sonic Zhang <[email protected]>--- include/linux/kgdb.h | 14 +++++++++++ kernel/kgdb.c | 64
+++++++++++++++++++++++++++++++++++++++++++-------
include/linux/kgdb.h struct kgdb_bkpt { · line 110
Quoted 11 lines
2 files changed, 69 insertions(+), 9 deletions(-)include/linux/kgdb.h +1
-0@@ -107,6 +107,7 @@ struct kgdb_bkpt {#endif #define KGDB_HW_BREAKPOINT 1 +#define KGDB_THR_PROC_SWAP 2
I can fix this later, but it should have always been a bit mask indicated by 0x1 0x2...
Quoted 11 lines
kernel/kgdb.c +1
-0@@ -566,6 +566,7 @@ static void kgdb_wait(struct pt_regs *regs) {unsigned long flags;int cpu; +struct task_struct *thread;local_irq_save (flags); cpu =raw_smp_processor_id ();
kernel/kgdb.c static void kgdb_wait(struct pt_regs *regs) · line 583
Quoted 5 lines
kernel/kgdb.c +2
-0@@ -578,6 +579,8 @@ static void kgdb_wait(struct pt_regs *regs)smp_wmb ();atomic_set (&cpu_in_kgdb[cpu],1 ); +kgdb_disable_hw_debug (regs); +
Good catch, this is a real arch independent defect, which should be fixed.
kernel/kgdb.c static int gdb_serial_stub(struct kgdb_state *ks) · line 1256
Quoted 6 lines
kernel/kgdb.c +1
-1@@ -1223,7 +1253,13 @@ static int gdb_serial_stub(struct kgdb_state *ks)/* Clear the out buffer. */ memset (remcom_out_buffer,0 ,sizeof (remcom_out_buffer)); -if (kgdb_connected) { +if (kgdb_contthread) {
I thik that check needs to be
if (arch_kgdb_ops.flags & KGDB_THR_PROC_SWAP &&
kgdb_contthread)
Although I am not quite certain, and ther was no way to further look at it since your patch did not apply.
The use of contthread changed a bit in the 2.6.27, as it was found to not be doing what it was intended.
See commit d7161a65341556bacb5e6654e133803f46f51063 for the details.
kernel/kgdb.c static int gdb_serial_stub(struct kgdb_state *ks) · line 1265
Quoted 9 lines
kernel/kgdb.c +6
-0+ remcom_out_buffer[0 ] ='O' ; + remcom_out_buffer[1 ] ='K' ; + remcom_out_buffer[2 ] =0 ; +put_packet (remcom_out_buffer); + kgdb_contthread =NULL ; + }else if (kgdb_connected) {unsigned char thref[8 ];char *ptr;
Jason.