Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys



>    - You still need to take care of the Linux sched_param translation

here's sched_linux2native/sched_native2linux.  not tested at all.

YAMAMOTO Takashi
/*
 * linux realtime priority
 *
 * - SCHED_RR and SCHED_FIFO tasks have priorities [1,99].
 *
 * - SCHED_OTHER tasks don't have realtime priorities.
 *   in particular, sched_param::sched_priority is always 0.
 */

#define LINUX_SCHED_RTPRIO_MIN  1
#define LINUX_SCHED_RTPRIO_MAX  99

static int
sched_linux2native(int linux_policy, struct linux_sched_param *linux_params,
    int *native_policy, struct sched_param *native_params)
{

        switch (linux_policy) {
        case LINUX_SCHED_OTHER:
                if (native_policy != NULL) {
                        *native_policy = SCHED_OTHER;
                }
                break;

        case LINUX_SCHED_FIFO:
                if (native_policy != NULL) {
                        *native_policy = SCHED_FIFO;
                }
                break;

        case LINUX_SCHED_RR:
                if (native_policy != NULL) {
                        *native_policy = SCHED_RR;
                }
                break;

        default:
                return EINVAL;
        }

        if (linux_params != NULL) {
                int prio = linux_params->sched_priority;
        
                KASSERT(native_params != NULL);

                if (linux_policy == LINUX_SCHED_OTHER) {
                        if (prio != 0) {
                                return EINVAL;
                        }
                        native_params->sched_priority = PRI_NONE; /* XXX */
                } else {
                        if (prio < LINUX_SCHED_RTPRIO_MIN ||
                            prio > LINUX_SCHED_RTPRIO_MAX) {
                                return EINVAL;
                        }
                        native_params->sched_priority =
                            (prio - LINUX_SCHED_RTPRIO_MIN)
                            * (SCHED_PRI_MAX - SCHED_PRI_MIN)
                            / (LINUX_SCHED_RTPRIO_MAX - LINUX_SCHED_RTPRIO_MIN)
                            + SCHED_PRI_MIN;
                }
        }

        return 0;
}

static int
sched_native2linux(int native_policy, struct sched_param *native_params,
    int *linux_policy, struct linux_sched_param *linux_params)
{

        switch (native_policy) {
        case SCHED_OTHER:
                if (linux_policy != NULL) {
                        *linux_policy = LINUX_SCHED_OTHER;
                }
                break;

        case SCHED_FIFO:
                if (linux_policy != NULL) {
                        *linux_policy = LINUX_SCHED_FIFO;
                }
                break;

        case SCHED_RR:
                if (linux_policy != NULL) {
                        *linux_policy = LINUX_SCHED_RR;
                }
                break;

        default:
                panic("%s: unknown policy %d\n", __func__, native_policy);
        }

        if (native_params != NULL) {
                int prio = native_params->sched_priority;

                KASSERT(prio >= SCHED_PRI_MIN);
                KASSERT(prio <= SCHED_PRI_MAX);
                KASSERT(linux_params != NULL);

                if (native_policy == SCHED_OTHER) {
                        linux_params->sched_priority = 0;
                } else {
                        linux_params->sched_priority =
                            (prio - SCHED_PRI_MIN)
                            * (LINUX_SCHED_RTPRIO_MAX - LINUX_SCHED_RTPRIO_MIN)
                            / (SCHED_PRI_MAX - SCHED_PRI_MIN)
                            + LINUX_SCHED_RTPRIO_MIN;
                }
        }

        return 0;
}


Home | Main Index | Thread Index | Old Index