Re: [PATCH v2 2/5] util: allow virProcessSetScheduler to set SCHED_DEADLINE

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

 



On Mon, Nov 21, 2016 at 01:56:05PM +0100, Martin Polednik wrote:
As sched_deadline is linux specific, it is not set through
sched_setscheduler but rather the sched_setattr syscall. Additionally,
the scheduler has new set of parameters: runtime, deadline and period.

In this part of the series, we extend virProcessSetScheduler to
accommodate the additional parameters and use sched_setattr syscall to
set SCHED_DEADLINE. Another small addition is sched_attr struct, which
is required for sched_setattr and not exposed from the kernel or
libraries.
---
src/qemu/qemu_process.c |  3 ++-
src/util/virprocess.c   | 37 +++++++++++++++++++++++++++++++++----
src/util/virprocess.h   | 25 ++++++++++++++++++++++++-
3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3552a31..e984ccd 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2395,7 +2395,8 @@ qemuProcessSetupPid(virDomainObjPtr vm,

    /* Set scheduler type and priority. */
    if (sched &&
-        virProcessSetScheduler(pid, sched->policy, sched->priority) < 0)
+        virProcessSetScheduler(pid, sched->policy, sched->priority,
+                               sched->runtime, sched->deadline, sched->period) < 0)
        goto cleanup;

    ret = 0;
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9b4a555..acf4d6b 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -67,6 +67,7 @@
VIR_LOG_INIT("util.process");

#ifdef __linux__
+# include <sys/syscall.h>
/*
 * Workaround older glibc. While kernel may support the setns
 * syscall, the glibc wrapper might not exist. If that's the
@@ -87,10 +88,8 @@ VIR_LOG_INIT("util.process");
#   define __NR_setns 339
#  endif
# endif
-
# ifndef HAVE_SETNS
#  if defined(__NR_setns)
-#   include <sys/syscall.h>

static inline int setns(int fd, int nstype)
{
@@ -100,6 +99,24 @@ static inline int setns(int fd, int nstype)
#   error Please determine the syscall number for setns on your architecture
#  endif
# endif
+
+# if defined(SCHED_DEADLINE) && defined(__NR_sched_setattr)
+static inline int sched_setattr(pid_t pid,
+                                const struct sched_attr *attr,
+                                unsigned int flags)
+{
+    return syscall(__NR_sched_setattr, pid, attr, flags);
+}
+# else
+static inline int sched_setattr(pid_t pid,
+                                const struct sched_attr *attr,
+                                unsigned int flags)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Deadline scheduler is not supported on this platform."));
+    return -1;
+}
+# endif

As I said, no need to do that, just use AC_CHECK_FUNCS_ONCE we already
have in configure.ac.  Don't redefine it, just error out if it's not
available.

#else /* !__linux__ */
static inline int setns(int fd ATTRIBUTE_UNUSED, int nstype ATTRIBUTE_UNUSED)
{
@@ -1234,10 +1251,16 @@ virProcessSchedTranslatePolicy(virProcessSchedPolicy policy)
int
virProcessSetScheduler(pid_t pid,
                       virProcessSchedPolicy policy,
-                       int priority)
+                       int priority,
+                       unsigned long long runtime,
+                       unsigned long long deadline,
+                       unsigned long long period)
{
    struct sched_param param = {0};
+    struct sched_attr attrs = { sizeof(attrs), SCHED_DEADLINE, 0, 0, 0,
+                                runtime, deadline, period };
    int pol = virProcessSchedTranslatePolicy(policy);
+    int ret = 0;

    VIR_DEBUG("pid=%lld, policy=%d, priority=%u",
              (long long) pid, policy, priority);
@@ -1280,7 +1303,13 @@ virProcessSetScheduler(pid_t pid,
        param.sched_priority = priority;
    }

-    if (sched_setscheduler(pid, pol, &param) < 0) {
+    if (pol == SCHED_DEADLINE) {
+        ret = sched_setattr(pid, &attrs, 0);
+    } else {
+        ret = sched_setscheduler(pid, pol, &param);
+    }
+
+    if (ret < 0) {
        virReportSystemError(errno,
                             _("Cannot set scheduler parameters for pid %lld"),
                             (long long) pid);
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 1eac3e6..02522b4 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -41,6 +41,26 @@ typedef enum {

VIR_ENUM_DECL(virProcessSchedPolicy);

+# ifdef SCHED_DEADLINE
+struct sched_attr {
+    uint32_t size;
+
+    uint32_t sched_policy;
+    uint64_t sched_flags;
+
+    /* SCHED_NORMAL, SCHED_BATCH */
+    uint32_t sched_nice;
+
+    /* SCHED_FIFO, SCHED_RR */
+    uint32_t sched_priority;
+
+    /* SCHED_DEADLINE (nsec) */
+    uint64_t sched_runtime;
+    uint64_t sched_deadline;
+    uint64_t sched_period;
+};
+# endif
+

There's no need to expose this in a header file, move it to virprocess.c.

char *
virProcessTranslateStatus(int status);

@@ -93,6 +113,9 @@ int virProcessRunInMountNamespace(pid_t pid,

int virProcessSetScheduler(pid_t pid,
                           virProcessSchedPolicy policy,
-                           int priority);
+                           int priority,
+                           unsigned long long runtime,
+                           unsigned long long deadline,
+                           unsigned long long period);

#endif /* __VIR_PROCESS_H__ */
--
2.8.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: Digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux