2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2016-08-07 16:25:30 +02:00
|
|
|
* sched/pthread/pthread_getschedparam.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2024-09-11 13:45:11 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-08 16:33:58 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
2018-01-30 18:07:36 +01:00
|
|
|
|
|
|
|
#include <nuttx/sched.h>
|
|
|
|
|
2014-08-08 20:55:02 +02:00
|
|
|
#include "pthread/pthread.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2015-10-03 15:25:53 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: pthread_getschedparam
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2007-03-24 16:51:50 +01:00
|
|
|
* The pthread_getschedparam() functions will get the scheduling policy and
|
|
|
|
* parameters of threads. For SCHED_FIFO and SCHED_RR, the only required
|
|
|
|
* member of the sched_param structure is the priority sched_priority.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
* The pthread_getschedparam() function will retrieve the scheduling
|
|
|
|
* policy and scheduling parameters for the thread whose thread ID is
|
|
|
|
* given by 'thread' and will store those values in 'policy' and 'param',
|
2007-03-24 16:51:50 +01:00
|
|
|
* respectively. The priority value returned from pthread_getschedparam()
|
|
|
|
* will be the value specified by the most recent pthread_setschedparam(),
|
|
|
|
* pthread_setschedprio(), or pthread_create() call affecting the target
|
2012-07-14 21:30:31 +02:00
|
|
|
* thread. It will not reflect any temporary adjustments to its priority
|
|
|
|
* (such as might result of any priority inheritance, for example).
|
2007-03-24 16:51:50 +01:00
|
|
|
*
|
|
|
|
* The policy parameter may have the value SCHED_FIFO, or SCHED_RR
|
|
|
|
* (SCHED_OTHER and SCHED_SPORADIC, in particular, are not supported).
|
|
|
|
* The SCHED_FIFO and SCHED_RR policies will have a single scheduling
|
|
|
|
* parameter, sched_priority.
|
2015-10-08 04:13:49 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2007-03-24 16:51:50 +01:00
|
|
|
* thread - The ID of thread whose scheduling parameters will be queried.
|
|
|
|
* policy - The location to store the thread's scheduling policy.
|
|
|
|
* param - The location to store the thread's priority.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-03-24 16:51:50 +01:00
|
|
|
* 0 if successful. Otherwise, the error code ESRCH if the value specified
|
|
|
|
* by thread does not refer to an existing thread.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
2012-07-14 21:30:31 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-07-14 21:30:31 +02:00
|
|
|
int pthread_getschedparam(pthread_t thread, FAR int *policy,
|
|
|
|
FAR struct sched_param *param)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2022-06-30 19:34:24 +02:00
|
|
|
sinfo("Thread ID=%d policy=%p param=%p\n", thread, policy, param);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-01-30 18:07:36 +01:00
|
|
|
if (policy == NULL || param == NULL)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
|
|
|
ret = EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
/* Get the scheduler parameters of the thread. */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_get_param((pid_t)thread, param);
|
2018-01-30 18:07:36 +01:00
|
|
|
if (ret < 0)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2018-01-30 18:07:36 +01:00
|
|
|
ret = -ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-06 16:13:16 +01:00
|
|
|
/* Get the scheduler policy. */
|
|
|
|
|
2020-05-09 16:04:45 +02:00
|
|
|
ret = nxsched_get_scheduler((pid_t)thread);
|
2018-02-06 16:13:16 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
ret = -ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*policy = ret;
|
|
|
|
ret = OK;
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 00:42:42 +02:00
|
|
|
sinfo("Returning %d\n", ret);
|
2007-02-18 00:21:28 +01:00
|
|
|
return ret;
|
|
|
|
}
|