Ticket #3421: mythtv_jobqueue_ionice.diff

File mythtv_jobqueue_ionice.diff, 6.5 KB (added by rd.mora@…, 14 years ago)

Patch to set I/O nice level to idle on jobqueue processes (not production ready)

  • libs/libmythtv/jobqueue.cpp

     
    488488            }
    489489        }
  • libs/libmyth/util.cpp

    -        if (startedJobAlready)
    -            sleep(5);
    -        else
    -            sleep(sleepTime);
    +        sleep(sleepTime);
         }
     }
    
    @@ -1775,2 +1772,2 @@
             path = tokens[0];
         }
    
    +    int flags = 0;
         if (jobQueueCPU < 2)
    -        nice(17);
    +    {
    +        flags = MYTH_SYSTEM_IOPRIO_IDLE;
    +        flags |= MYTH_SYSTEM_NICE_LOW_PRIO;
    +    }
    
         QString transcoderName;
         if (transcoder == RecordingProfile::TranscoderAutodetect)
    @@ -1836,2 +1837,2 @@
             VERBOSE(VB_JOBQUEUE, LOC + QString("Running command: '%1'")
                                                .arg(command));
    
    -        int result = myth_system(command);
    +        int result = myth_system(command, flags);
             int status = GetJobStatus(jobID);
    
             if ((result == MYTHSYSTEM__EXIT__EXECL_ERROR) ||
    @@ -2023,2 +2024,2 @@
             path = tokens[0];
         }
    
    +    int flags = 0;
    +    switch (jobQueueCPU)
    +    {
    +        case  0: flags = MYTH_SYSTEM_IOPRIO_IDLE;
    +                 flags |= MYTH_SYSTEM_NICE_LOW_PRIO;
    +                 break;
    +        case  1: flags = MYTH_SYSTEM_IOPRIO_IDLE;
    +                 flags |= MYTH_SYSTEM_NICE_MEDIUM_PRIO;
    +                 break;
    +        case  2:
    +        default: break;
    +    }
    +
         VERBOSE(VB_JOBQUEUE, LOC + QString("Running command: '%1'").arg(command));
    
    -    breaksFound = myth_system(command);
    +    breaksFound = myth_system(command, flags);
         int priority = LP_NOTICE;
         QString comment = "";
    
    @@ -2121,2 +2135,2 @@
         gContext->LogEntry("jobqueue", LP_NOTICE,
                            QString("Job \"%1\" Started").arg(jobDesc), msg);
    
    +    int flags = 0;
         switch (jobQueueCPU)
         {
    -        case  0: nice(17);
    +        case  0: flags = MYTH_SYSTEM_IOPRIO_IDLE;
    +                 flags |= MYTH_SYSTEM_NICE_LOW_PRIO;
                      break;
    -        case  1: nice(10);
    +        case  1: flags = MYTH_SYSTEM_IOPRIO_IDLE;
    +                 flags |= MYTH_SYSTEM_NICE_MEDIUM_PRIO;
                      break;
             case  2:
             default: break;
    @@ -2134,2 +2151,2 @@
         VERBOSE(VB_JOBQUEUE, LOC + QString("Running command: '%1'")
                                            .arg(runningJobCommands[key]));
    
    -    int result = myth_system(runningJobCommands[key]);
    +    int result = myth_system(runningJobCommands[key], flags);
    
         if ((result == MYTHSYSTEM__EXIT__EXECL_ERROR) ||
             (result == MYTHSYSTEM__EXIT__CMD_NOT_FOUND))
     
    5252#include "jsmenuevent.h"
    5353#endif
  • libs/libmyth/util.h

    +// @TODO: make this a configure option
    +#define USE_IOPRIO_IDLE
    +#ifdef USE_IOPRIO_IDLE
    +// From /usr/src/linux/Documentation/block/ioprio.txt
    +#include <asm/unistd.h>
    +extern int sys_ioprio_set(int, int, int);
    +extern int sys_ioprio_get(int, int);
    +
    +#if defined(__i386__)
    +#define __NR_ioprio_set         289
    +#define __NR_ioprio_get         290
    +#elif defined(__ppc__)
    +#define __NR_ioprio_set         273
    +#define __NR_ioprio_get         274
    +#elif defined(__x86_64__)
    +#define __NR_ioprio_set         251
    +#define __NR_ioprio_get         252
    +#elif defined(__ia64__)
    +#define __NR_ioprio_set         1274
    +#define __NR_ioprio_get         1275
    +#else
    +#error "Unsupported arch"
    +#endif
    +
    +_syscall3(int, ioprio_set, int, which, int, who, int, ioprio);
    +_syscall2(int, ioprio_get, int, which, int, who);
    +
    +enum {
    +        IOPRIO_CLASS_NONE,
    +        IOPRIO_CLASS_RT,
    +        IOPRIO_CLASS_BE,
    +        IOPRIO_CLASS_IDLE,
    +};
    +
    +enum {
    +        IOPRIO_WHO_PROCESS = 1,
    +        IOPRIO_WHO_PGRP,
    +        IOPRIO_WHO_USER,
    +};
    +
    +#define IOPRIO_CLASS_SHIFT      13
    +#endif /* USE_IOPRIO_IDLE */
    +
     /** \fn mythCurrentDateTime()
      *  \brief Returns the current QDateTime object, stripped of its msec component
      */
    @@ -250,2 +293,2 @@
             if (fd != 0)
                 close(fd);
    
    +#ifdef USE_IOPRIO_IDLE
    +        /* Set io priority if required */
    +        if(flags & MYTH_SYSTEM_IOPRIO_IDLE)
    +            if(ioprio_set(IOPRIO_WHO_PROCESS, 0, 7 | IOPRIO_CLASS_IDLE << IOPRIO_CLASS_SHIFT) == -1)
    +                VERBOSE(VB_IMPORTANT, "Error setting IO Priority!");
    +#endif
    +
    +        if (((flags & MYTH_SYSTEM_NICE_MEDIUM_PRIO) && setpriority(PRIO_PROCESS, 0, 10)) ||
    +            ((flags & MYTH_SYSTEM_NICE_LOW_PRIO) && setpriority(PRIO_PROCESS, 0, 19)))
    +            VERBOSE(VB_IMPORTANT, "Setting priority of child process failed.");
    +
             /* Run command */
             execl("/bin/sh", "sh", "-c", QString(command.utf8()).ascii(), NULL);
             if (errno)
  • programs/mythbackend/housekeeper.cpp

     #include "mythexp.h"
    
    -#define MYTH_SYSTEM_DONT_BLOCK_LIRC          0x1 //< myth_system() flag to avoid blocking
    -#define MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU 0x2 //< myth_system() flag to avoid blocking
    +#define MYTH_SYSTEM_DONT_BLOCK_LIRC          0x01 //< myth_system() flag to avoid blocking
    +#define MYTH_SYSTEM_DONT_BLOCK_JOYSTICK_MENU 0x02 //< myth_system() flag to avoid blocking
    +#define MYTH_SYSTEM_IOPRIO_IDLE              0x04 //< myth_system() flag to use idle io priority
    +#define MYTH_SYSTEM_NICE_LOW_PRIO            0x08 //< myth_system() nice child to low priority (19)
    +#define MYTH_SYSTEM_NICE_MEDIUM_PRIO         0x10 //< myth_system() nice child to medium priority (10)
    
     class QPixmap;
     class QImage;
     
    312312        command = QString("%1 %2 >>%3 2>&1").arg(mfpath).arg(mfarg).arg(mflog);