Skip to content

Commit

Permalink
os: remove config dependency to fix ps command issue
Browse files Browse the repository at this point in the history
Due to config dependency, ps command doesn't give correct output.
So, this patch fix the issue by removing config dependency for
CONFIG_SMP and CONFIG_SMP_NCPUS between Kernel and application.
We hande it by introducing the syscall for obtaining the number
CPUs while runtime.

Signed-off-by: neel-samsung <[email protected]>
  • Loading branch information
neel-samsung committed Jan 16, 2025
1 parent a25867b commit 65b699c
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion os/fs/procfs/fs_procfsproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static ssize_t proc_entry_stat(FAR struct proc_file_s *procfile, FAR struct tcb_
#ifdef CONFIG_SMP
linesize = snprintf(procfile->line, STATUS_LINELEN, "%d %d %d %d %d %d %d %d %d %d", tcb->pid, ppid, tcb->sched_priority, tcb->flags, tcb->task_state, tcb->adj_stack_size, peak_stack, curr_heap, peak_heap, tcb->cpu);
#else
linesize = snprintf(procfile->line, STATUS_LINELEN, "%d %d %d %d %d %d %d %d %d", tcb->pid, ppid, tcb->sched_priority, tcb->flags, tcb->task_state, tcb->adj_stack_size, peak_stack, curr_heap, peak_heap);
linesize = snprintf(procfile->line, STATUS_LINELEN, "%d %d %d %d %d %d %d %d %d %d", tcb->pid, ppid, tcb->sched_priority, tcb->flags, tcb->task_state, tcb->adj_stack_size, peak_stack, curr_heap, peak_heap, 0);
#endif
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen, &offset);
totalsize += copysize;
Expand Down
1 change: 1 addition & 0 deletions os/include/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ int sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask);
int sched_cpucount(FAR const cpu_set_t *set);
int sched_getcpu(void);
#endif /* CONFIG_SMP */
int sched_getcpucount(void);

/* Task Switching Interfaces (non-standard) */
/**
Expand Down
3 changes: 2 additions & 1 deletion os/include/sys/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
#define SYS_sched_getaffinity (CONFIG_SYS_RESERVED + 14)
#define SYS_sched_setaffinity (CONFIG_SYS_RESERVED + 15)
#define SYS_sched_getcpu (CONFIG_SYS_RESERVED + 16)
#define __SYS_sem (CONFIG_SYS_RESERVED + 17)
#define SYS_sched_getcpucount (CONFIG_SYS_RESERVED + 17)
#define __SYS_sem (CONFIG_SYS_RESERVED + 18)

/* Semaphores */

Expand Down
2 changes: 0 additions & 2 deletions os/include/tinyara/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ enum tstate_e {
TSTATE_TASK_INVALID = 0, /* INVALID - The TCB is uninitialized */
TSTATE_TASK_PENDING, /* READY_TO_RUN - Pending preemption unlock */
TSTATE_TASK_READYTORUN, /* READY-TO-RUN - But not running */
#ifdef CONFIG_SMP
TSTATE_TASK_ASSIGNED, /* READY-TO-RUN - Not running, but assigned to a CPU */
#endif
TSTATE_TASK_RUNNING, /* READY_TO_RUN - And running */

TSTATE_TASK_INACTIVE, /* BLOCKED - Initialized but not yet activated */
Expand Down
4 changes: 4 additions & 0 deletions os/kernel/init/os_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ const struct tasklist_s g_tasklisttable[NUM_TASK_STATES] =
&g_readytorun,
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE
},
{ /* TSTATE_TASK_ASSIGNED */
&g_readytorun,
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE
},
{ /* TSTATE_TASK_RUNNING */
&g_readytorun,
TLIST_ATTR_PRIORITIZED | TLIST_ATTR_RUNNABLE
Expand Down
5 changes: 5 additions & 0 deletions os/kernel/sched/sched_getcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ int sched_getcpu(void)
{
return up_cpu_index(); /* Does not fail */
}

int sched_getcpucount(void)
{
return CONFIG_SMP_NCPUS;
}
1 change: 1 addition & 0 deletions os/syscall/syscall.csv
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"sched_getaffinity","sched.h","","int","pid_t","size_t","FAR cpu_set_t *"
"sched_setaffinity","sched.h","","int","pid_t","size_t","FAR const cpu_set_t*"
"sched_getcpu", "sched.h", "", "int"
"sched_getcpucount" , "sched.h", "", "int"
"sched_getparam", "sched.h", "", "int", "pid_t", "struct sched_param*"
"sched_getscheduler", "sched.h", "", "int", "pid_t"
"sched_getstreams", "tinyara/sched.h", "CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0", "FAR struct streamlist*"
Expand Down
1 change: 1 addition & 0 deletions os/syscall/syscall_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SYSCALL_LOOKUP(set_errno, 1, STUB_set_errno)
SYSCALL_LOOKUP(sched_getaffinity, 3, STUB_sched_getaffinity)
SYSCALL_LOOKUP(sched_setaffinity, 3, STUB_sched_setaffinity)
SYSCALL_LOOKUP(sched_getcpu, 0, STUB_sched_getcpu)
SYSCALL_LOOKUP(sched_getcpucount, 0, STUB_sched_getcpucount)

/* Semaphores */

Expand Down
2 changes: 1 addition & 1 deletion os/syscall/syscall_stublookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ uintptr_t STUB_sched_setscheduler(int nbr, uintptr_t parm1, uintptr_t parm2,
int STUB_sched_getaffinity(pid_t pid, size_t cpusetsize, FAR cpu_set_t *mask);
int STUB_sched_setaffinity(pid_t pid, size_t cpusetsize, FAR const cpu_set_t *mask);
int STUB_sched_getcpu(void);
int STUB_sched_getcpucount(void);

uintptr_t STUB_sched_unlock(int nbr);
uintptr_t STUB_sched_yield(int nbr);

/* Semaphores */

uintptr_t STUB_sem_close(int nbr, uintptr_t parm1);
Expand Down

0 comments on commit 65b699c

Please sign in to comment.