Add interfaces to support getting/setting of thread/task names

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4658 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo
2012-04-26 15:00:35 +00:00
parent 414af0aef2
commit 305cf084d4
10 changed files with 296 additions and 9 deletions
+2
View File
@@ -2686,4 +2686,6 @@
* arch/arm/src/stm32/stm32_otgfs.c: The driver needs to reset the software (in * arch/arm/src/stm32/stm32_otgfs.c: The driver needs to reset the software (in
order to flush the requests) and to disable the software connection when the order to flush the requests) and to disable the software connection when the
device is unregistered. device is unregistered.
* include/sys/prctl.h, sched/prctl.c, include/pthread.h: Add interfaces to
support getting and setting of the thread or task name.
+12
View File
@@ -136,6 +136,18 @@
#define PTHREAD_BARRIER_SERIAL_THREAD 0x1000 #define PTHREAD_BARRIER_SERIAL_THREAD 0x1000
/* Definitions to map some non-standard, BSD thread management interfaces to
* the non-standard Linux-like prctl() interface. Since these are simple
* mappings to prctl, they will return 0 sucess and -1 on failure with the
* err number in errno. This is an inconsistency with out pthread interfaces.
*/
#define pthread_setname_np(thread, name) \
prctl((int)PR_SET_NAME, (char*)name, (int)thread)
#define pthread_getname_np(thread, name) \
prctl((int)PR_GET_NAME, (char*)name, (int)thread)
/******************************************************************************** /********************************************************************************
* Global Type Declarations * Global Type Declarations
********************************************************************************/ ********************************************************************************/
+115
View File
@@ -0,0 +1,115 @@
/****************************************************************************
* include/sys/prctl.h
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_SYS_PRCTL_H
#define __INCLUDE_SYS_PRCTL_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Supported prctl() commands.
*
*
* PR_SET_NAME
* Set the task (or thread) name for the thread whose ID is in required
* arg2 (int), using the value in the location pointed to by required arg1
* (char*). The name can be up to CONFIG_TASK_NAME_SIZE long (including
* any null termination). The thread ID of 0 will set the name of the
* calling thread. As an example:
*
* prctl(PR_SET_NAME, "MyName", 0);
*
* PR_GET_NAME
* Return the task (or thread) name for the for the thread whose ID is
* optional arg2 (int), in the buffer pointed to by optional arg1 (char *).
* The buffer must be CONFIG_TASK_NAME_SIZE long (including any null
* termination). As an example:
*
* char myname[CONFIG_TASK_NAME_SIZE];
* prctl(PR_GET_NAME, myname, 0);
*/
#define PR_SET_NAME 1
#define PR_GET_NAME 2
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C" {
#else
#define EXTERN extern
#endif
/****************************************************************************
* Name: prctl
*
* Description:
* prctl() is called with a first argument describing what to do (with
* values PR_* defined above) and with additional arguments depending on
* the specific command.
*
* Returned Value:
* The returned value may depend on the specific commnand. For PR_SET_NAME
* and PR_GET_NAME, the returned value of 0 indicates successful operation.
* On any failure, -1 is retruend and the errno value is set appropriately.
*
* EINVAL The value of 'option' is not recognized.
* EFAULT optional arg1 is not a valid address.
* ESRCH No task/thread can be found corresponding to that specified
* by optional arg1.
*
****************************************************************************/
EXTERN int prctl(int option, ...);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __INCLUDE_SYS_PRCTL_H */
+13 -4
View File
@@ -2,8 +2,8 @@
* include/sys/syscall.h * include/sys/syscall.h
* This file contains the system call numbers. * This file contains the system call numbers.
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -315,9 +315,18 @@
# define SYS_sendto (__SYS_network+8) # define SYS_sendto (__SYS_network+8)
# define SYS_setsockopt (__SYS_network+9) # define SYS_setsockopt (__SYS_network+9)
# define SYS_socket (__SYS_network+10) # define SYS_socket (__SYS_network+10)
# define SYS_maxsyscall (__SYS_network+11) # define SYS_nnetsocket (__SYS_network+11)
#else #else
# define SYS_maxsyscall __SYS_network # define SYS_nnetsocket __SYS_network
#endif
/* The following is defined only if CONFIG_TASK_NAME_SIZE > 0 */
#if CONFIG_TASK_NAME_SIZE > 0
# define SYS_prctl (SYS_nnetsocket+0)
# define SYS_maxsyscall (SYS_nnetsocket+1)
#else
# define SYS_maxsyscall SYS_nnetsocket
#endif #endif
/* Note that the reported number of system calls does *NOT* include the /* Note that the reported number of system calls does *NOT* include the
+2 -2
View File
@@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* include/syscall.h * include/syscall.h
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
+1 -1
View File
@@ -43,7 +43,7 @@ MISC_SRCS = os_start.c os_bringup.c errno_getptr.c errno_get.c errno_set.c \
sched_getstreams.c sched_setupidlefiles.c sched_setuptaskfiles.c \ sched_getstreams.c sched_setupidlefiles.c sched_setuptaskfiles.c \
sched_setuppthreadfiles.c sched_releasefiles.c sched_setuppthreadfiles.c sched_releasefiles.c
TSK_SRCS = task_create.c task_init.c task_setup.c task_activate.c \ TSK_SRCS = prctl.c task_create.c task_init.c task_setup.c task_activate.c \
task_start.c task_delete.c task_deletecurrent.c task_exithook.c \ task_start.c task_delete.c task_deletecurrent.c task_exithook.c \
task_restart.c exit.c getpid.c sched_addreadytorun.c \ task_restart.c exit.c getpid.c sched_addreadytorun.c \
sched_removereadytorun.c sched_addprioritized.c sched_mergepending.c \ sched_removereadytorun.c sched_addprioritized.c sched_mergepending.c \
+138
View File
@@ -0,0 +1,138 @@
/************************************************************************
* sched/prctl.c
*
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************************/
/************************************************************************
* Included Files
************************************************************************/
#include <nuttx/config.h>
#include <sys/prctl.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/sched.h>
#include "os_internal.h"
/************************************************************************
* Private Functions
************************************************************************/
/************************************************************************
* Public Functions
************************************************************************/
/****************************************************************************
* Name: prctl
*
* Description:
* prctl() is called with a first argument describing what to do (with
* values PR_* defined above) and with additional arguments depending on
* the specific command.
*
* Returned Value:
* The returned value may depend on the specific commnand. For PR_SET_NAME
* and PR_GET_NAME, the returned value of 0 indicates successful operation.
* On any failure, -1 is retruend and the errno value is set appropriately.
*
* EINVAL The value of 'option' is not recognized.
* EFAULT optional arg1 is not a valid address.
* ESRCH No task/thread can be found corresponding to that specified
* by optional arg1.
*
****************************************************************************/
int prctl(int option, ...)
{
va_list ap;
int err;
va_start(ap, option);
switch (option)
{
case PR_SET_NAME:
case PR_GET_NAME:
#if CONFIG_TASK_NAME_SIZE > 0
{
int pid = va_arg(ap, int);
char *name = va_arg(ap, char *);
FAR _TCB *tcb = sched_gettcb(pid);
if (!tcb)
{
sdbg("Pid does not correspond to a task: %d\n", pid);
err = ESRCH;
goto errout;
}
if (!name)
{
sdbg("No name provide\n");
err = EFAULT;
goto errout;
}
if (option == PR_SET_NAME)
{
strncpy(tcb->name, name, CONFIG_TASK_NAME_SIZE);
}
else
{
strncpy(name, tcb->name, CONFIG_TASK_NAME_SIZE-1);
name[CONFIG_TASK_NAME_SIZE-1];
}
}
break;
#else
sdbg("Option not enabled: %d\n", option);
err = ENOSYS;
goto errout;
#endif
default:
sdbg("Unrecognized option: %d\n", option);
err = EINVAL;
goto errout;
}
va_end(ap);
return OK;
errout:
va_end(ap);
set_errno(err);
return ERROR;
}
+6 -2
View File
@@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* syscall/syscall_stublookup.c * syscall/syscall_stublookup.c
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -230,6 +230,10 @@ extern uintptr_t STUB_sendto(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3,
extern uintptr_t STUB_setsockopt(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5); extern uintptr_t STUB_setsockopt(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5);
extern uintptr_t STUB_socket(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3); extern uintptr_t STUB_socket(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3);
/* The following is defined only if CONFIG_TASK_NAME_SIZE > 0 */
extern uintptr_t STUB_prctl(uintptr_t parm1, uintptr_t parm2, uintptr_t parm3, uintptr_t parm4, uintptr_t parm5);
/**************************************************************************** /****************************************************************************
* Public Data * Public Data
****************************************************************************/ ****************************************************************************/
+6
View File
@@ -247,6 +247,12 @@ STUB_LOOKUP(3, STUB_up_assert_code) /* SYS_up_assert_code */
STUB_LOOKUP(3, STUB_socket) /* SYS_socket */ STUB_LOOKUP(3, STUB_socket) /* SYS_socket */
#endif #endif
/* The following is defined only if CONFIG_TASK_NAME_SIZE > 0 */
#if CONFIG_TASK_NAME_SIZE > 0
STUB_LOOKUP(5, STUB_prctl) /* SYS_prctl */
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
+1
View File
@@ -39,6 +39,7 @@
"open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..." "open","fcntl.h","CONFIG_NFILE_DESCRIPTORS > 0","int","const char*","int","..."
"opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*" "opendir","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","FAR DIR*","FAR const char*"
"pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*" "pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*"
"prctl", sys/prctl.h, "CONFIG_TASK_NAME_SIZE > 0","int","int","..."
"clock_systimer","nuttx/clock.h","!defined(CONFIG_DISABLE_CLOCK)","uint32_t" "clock_systimer","nuttx/clock.h","!defined(CONFIG_DISABLE_CLOCK)","uint32_t"
"poll","poll.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","FAR struct pollfd*","nfds_t","int" "poll","poll.h","!defined(CONFIG_DISABLE_POLL) && (CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0)","int","FAR struct pollfd*","nfds_t","int"
"pthread_barrier_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*" "pthread_barrier_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_barrier_t*"
Can't render this file because it contains an unexpected character in line 42 and column 67.