Skip to content

Commit 1aab457

Browse files
hujun260xiaoxiang781216
authored andcommitted
sched:add parameters to restore_critical_section
reason: In SMP, when a context switch occurs, restore_critical_section is executed. To reduce the time taken for context switching, we directly pass the required parameters to restore_critical_section instead of acquiring them repeatedly. Signed-off-by: hujun5 <[email protected]>
1 parent 8439296 commit 1aab457

File tree

18 files changed

+67
-31
lines changed

18 files changed

+67
-31
lines changed

arch/arm/src/arm/arm_syscall.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454

5555
uint32_t *arm_syscall(uint32_t *regs)
5656
{
57+
struct tcb_s *tcb;
5758
uint32_t cmd;
59+
int cpu;
5860

5961
/* Nested interrupts are not supported */
6062

@@ -158,9 +160,13 @@ uint32_t *arm_syscall(uint32_t *regs)
158160
* assertion logic for reporting crashes.
159161
*/
160162

161-
g_running_tasks[this_cpu()] = this_task();
163+
cpu = this_cpu();
164+
tcb = current_task(cpu);
165+
g_running_tasks[cpu] = tcb;
162166

163-
restore_critical_section();
167+
/* Restore the cpu lock */
168+
169+
restore_critical_section(tcb, cpu);
164170
regs = (uint32_t *)CURRENT_REGS;
165171
}
166172

arch/arm/src/armv6-m/arm_svcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ int arm_svcall(int irq, void *context, void *arg)
478478

479479
if (regs != CURRENT_REGS)
480480
{
481-
restore_critical_section();
481+
restore_critical_section(this_task(), this_cpu());
482482
}
483483

484484
return OK;

arch/arm/src/armv7-a/arm_syscall.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ static void dispatch_syscall(void)
160160

161161
uint32_t *arm_syscall(uint32_t *regs)
162162
{
163+
struct tcb_s *tcb;
163164
uint32_t cmd;
165+
int cpu;
164166
#ifdef CONFIG_BUILD_KERNEL
165167
uint32_t cpsr;
166168
#endif
@@ -590,9 +592,13 @@ uint32_t *arm_syscall(uint32_t *regs)
590592
* assertion logic for reporting crashes.
591593
*/
592594

593-
g_running_tasks[this_cpu()] = this_task();
595+
cpu = this_cpu();
596+
tcb = current_task(cpu);
597+
g_running_tasks[cpu] = tcb;
594598

595-
restore_critical_section();
599+
/* Restore the cpu lock */
600+
601+
restore_critical_section(tcb, cpu);
596602
regs = (uint32_t *)CURRENT_REGS;
597603
}
598604

arch/arm/src/armv7-m/arm_svcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ int arm_svcall(int irq, void *context, void *arg)
487487

488488
if (regs != CURRENT_REGS)
489489
{
490-
restore_critical_section();
490+
restore_critical_section(this_task(), this_cpu());
491491
}
492492

493493
return OK;

arch/arm/src/armv7-r/arm_syscall.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ static void dispatch_syscall(void)
156156

157157
uint32_t *arm_syscall(uint32_t *regs)
158158
{
159+
struct tcb_s *tcb;
159160
uint32_t cmd;
161+
int cpu;
160162
#ifdef CONFIG_BUILD_PROTECTED
161163
uint32_t cpsr;
162164
#endif
@@ -567,9 +569,13 @@ uint32_t *arm_syscall(uint32_t *regs)
567569
* assertion logic for reporting crashes.
568570
*/
569571

570-
g_running_tasks[this_cpu()] = this_task();
572+
cpu = this_cpu();
573+
tcb = current_task(cpu);
574+
g_running_tasks[cpu] = tcb;
571575

572-
restore_critical_section();
576+
/* Restore the cpu lock */
577+
578+
restore_critical_section(tcb, cpu);
573579
regs = (uint32_t *)CURRENT_REGS;
574580
}
575581

arch/arm/src/armv8-m/arm_svcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ int arm_svcall(int irq, void *context, void *arg)
488488

489489
if (regs != CURRENT_REGS)
490490
{
491-
restore_critical_section();
491+
restore_critical_section(this_task(), this_cpu());
492492
}
493493

494494
return OK;

arch/arm/src/armv8-r/arm_syscall.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ static void dispatch_syscall(void)
156156

157157
uint32_t *arm_syscall(uint32_t *regs)
158158
{
159+
struct tcb_s *tcb;
159160
uint32_t cmd;
161+
int cpu;
160162
#ifdef CONFIG_BUILD_PROTECTED
161163
uint32_t cpsr;
162164
#endif
@@ -567,9 +569,13 @@ uint32_t *arm_syscall(uint32_t *regs)
567569
* assertion logic for reporting crashes.
568570
*/
569571

570-
g_running_tasks[this_cpu()] = this_task();
572+
cpu = this_cpu();
573+
tcb = current_task(cpu);
574+
g_running_tasks[cpu] = tcb;
571575

572-
restore_critical_section();
576+
/* Restore the cpu lock */
577+
578+
restore_critical_section(tcb, cpu);
573579
regs = (uint32_t *)CURRENT_REGS;
574580
}
575581

arch/arm64/src/common/arm64_syscall.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ uint64_t *arm64_syscall_switch(uint64_t * regs)
161161
uint64_t cmd;
162162
struct regs_context *f_regs;
163163
uint64_t *ret_regs;
164+
struct tcb_s *tcb;
165+
int cpu;
164166

165167
/* Nested interrupts are not supported */
166168

@@ -252,11 +254,13 @@ uint64_t *arm64_syscall_switch(uint64_t * regs)
252254
* assertion logic for reporting crashes.
253255
*/
254256

255-
g_running_tasks[this_cpu()] = this_task();
257+
cpu = this_cpu();
258+
tcb = current_task(cpu);
259+
g_running_tasks[cpu] = tcb;
256260

257261
/* Restore the cpu lock */
258262

259-
restore_critical_section();
263+
restore_critical_section(tcb, cpu);
260264
}
261265

262266
return ret_regs;

arch/risc-v/src/common/riscv_swint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ int riscv_swint(int irq, void *context, void *arg)
501501

502502
if (regs != CURRENT_REGS)
503503
{
504-
restore_critical_section();
504+
restore_critical_section(this_task(), this_cpu());
505505
}
506506

507507
return OK;

arch/risc-v/src/common/supervisor/riscv_perform_syscall.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
void *riscv_perform_syscall(uintreg_t *regs)
3939
{
40+
struct tcb_s *tcb;
41+
int cpu;
42+
4043
/* Set up the interrupt register set needed by swint() */
4144

4245
CURRENT_REGS = regs;
@@ -64,11 +67,13 @@ void *riscv_perform_syscall(uintreg_t *regs)
6467
* assertion logic for reporting crashes.
6568
*/
6669

67-
g_running_tasks[this_cpu()] = this_task();
70+
cpu = this_cpu();
71+
tcb = current_task(cpu);
72+
g_running_tasks[cpu] = tcb;
6873

6974
/* Restore the cpu lock */
7075

71-
restore_critical_section();
76+
restore_critical_section(tcb, cpu);
7277

7378
/* If a context switch occurred while processing the interrupt then
7479
* CURRENT_REGS may have change value. If we return any value

0 commit comments

Comments
 (0)