A series patch for priority.
Subsystems (21)
PATCH 11/15 drivers/s390: Replace hardcoding of 19 with MAX_NICE.
In reply to Dongsheng Yang--- drivers/s390/crypto/ap_bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/s390/crypto/ap_bus.c +1 -1
@@ -1803,7 +1803,7 @@ static int ap_poll_thread(void *data)int requests;struct ap_device *ap_dev; -set_user_nice (current,19 ); +set_user_nice (current,MAX_NICE );while (1 ) {if (ap_suspend_flag)return 0 ;
Signature · 1 line
1.8.2.1
PATCH 8/15 fs/hearbeat: Replace hardcoding of -20 with MIN_NICE.
In reply to Dongsheng Yang--- fs/ocfs2/cluster/heartbeat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ocfs2/cluster/heartbeat.c +1 -1
@@ -1107,7 +1107,7 @@ static int o2hb_thread(void *data)mlog (ML_HEARTBEAT |ML_KTHREAD ,"hb thread running\n" ); -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );/* Pin node */ o2nm_depend_this_node ();
Signature · 1 line
1.8.2.1
PATCH 3/15 workqueue: Replace hardcoding of -20 with MIN_NICE.
In reply to Dongsheng Yang--- kernel/workqueue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/workqueue.c +3 -3
@@ -100,10 +100,10 @@ enum {/* * Rescue workers are used only on emergencies and shared by -* all cpus. Give -20. +* all cpus. Give MIN_NICE. */ -RESCUER_NICE_LEVEL =-20 , -HIGHPRI_NICE_LEVEL =-20 , +RESCUER_NICE_LEVEL =MIN_NICE , +HIGHPRI_NICE_LEVEL =MIN_NICE , WQ_NAME_LEN = 24, };
Signature · 1 line
1.8.2.1
PATCH 5/15 tools/mq_perf_tests: Replace hardcoding of -20 with MIN_NICE.
In reply to Dongsheng Yang--- tools/testing/selftests/mqueue/mq_perf_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/mqueue/mq_perf_tests.c +2 -2
@@ -527,9 +527,9 @@ void increase_limits(void)while (try_set (max_msgsize, cur_max_msgsize +=1024 )) ; cur_max_msgsize =get (max_msgsize); -if (setpriority (PRIO_PROCESS ,0 ,-20 ) !=0 ) +if (setpriority (PRIO_PROCESS ,0 ,MIN_NICE ) !=0 )shutdown (2 ,"setpriority()" , __LINE__); - cur_nice =-20 ; + cur_nice =MIN_NICE ; }int main (int argc,char *argv[])
Signature · 1 line
1.8.2.1
cover A series patch for priority.
Hi all,
This patchset is all about priority.
1. Add two macros in prio.h named NICE_TO_RLIMIT and RLIMIT_TO_NICE. They are converting the value between nice value [-20, 19] and rlimit style value [1, 40].
2. Add a macro in ioprio.h named NICE_TO_IOPRIO.
It convert nice value [-20, 19] to io priority [0, 7].
3. Others are all about replace hardcoding value about nice to MIN_NICE or MAX_NICE.
Dongsheng Yang (14):
sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
workqueue: Replace hardcoding of -20 with MIN_NICE.
locktorture: Replace hardcoding of 19 with MAX_NICE. tools/mq_perf_tests: Replace hardcoding of -20 with MIN_NICE.
mm: Replace hardcoding of 19 with MAX_NICE.
ioprio: Add a macro named NICE_TO_IOPRIO.
fs/hearbeat: Replace hardcoding of -20 with MIN_NICE. driver/block: Replace hardcoding of -20 with MIN_NICE. driver/char: Replace hardcoding of 19 with MAX_NICE. drivers/s390: Replace hardcoding of 19 with MAX_NICE. driver/staging/android: Use RLIMIT_TO_NICE to replace opened code
implementation.
sched/prio: Add a macro named RLIMIT_TO_NICE in prio.h. driver/staging/lustre: Replace hardcoding of -20 with MIN_NICE. driver/scsi: Replace hardcoding of 20 with MIN_NICE.
Joe Perches (1):
kernel/sys: Replace opened code implementation with NICE_TO_RLIMIT
macro.
drivers/block/loop.c | 2 +- drivers/block/nbd.c | 2 +- drivers/block/pktcdvd.c | 2 +- drivers/char/ipmi/ipmi_si_intf.c | 2 +- drivers/s390/crypto/ap_bus.c | 2 +- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 4 +- drivers/scsi/bnx2i/bnx2i_hwi.c | 2 +- drivers/scsi/fcoe/fcoe.c | 2 +- drivers/scsi/ibmvscsi/ibmvfc.c | 2 +- drivers/scsi/ibmvscsi/ibmvscsi.c | 2 +- drivers/scsi/lpfc/lpfc_hbadisc.c | 2 +- drivers/scsi/qla2xxx/qla_os.c | 2 +- drivers/staging/android/binder.c | 4 +- drivers/staging/lustre/lustre/llite/lloop.c | 2 +- fs/ocfs2/cluster/heartbeat.c | 2 +- include/linux/ioprio.h | 7 +- include/linux/sched/prio.h | 6 + kernel/locking/locktorture.c | 2 +- kernel/sys.c | 206 ++++++++++++------------- kernel/workqueue.c | 6 +- mm/huge_memory.c | 2 +- tools/testing/selftests/mqueue/mq_perf_tests.c | 4 +- 22 files changed, 139 insertions(+), 128 deletions(-)
Signature · 1 line
1.8.2.1
PATCH 4/15 locktorture: Replace hardcoding of 19 with MAX_NICE.
--- kernel/locking/locktorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/locking/locktorture.c +1 -1
@@ -216,7 +216,7 @@ static int lock_torture_writer(void *arg)static DEFINE_TORTURE_RANDOM (rand);VERBOSE_TOROUT_STRING ("lock_torture_writer task started" ); -set_user_nice (current,19 ); +set_user_nice (current,MAX_NICE ); do { schedule_timeout_uninterruptible(1);
Signature · 1 line
1.8.2.1
PATCH 6/15 mm: Replace hardcoding of 19 with MAX_NICE.
In reply to Dongsheng Yang--- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
@@ -2803,7 +2803,7 @@ static int khugepaged(void *none)struct mm_slot *mm_slot;set_freezable (); -set_user_nice (current,19 ); +set_user_nice (current,MAX_NICE );while (!kthread_should_stop ()) {khugepaged_do_scan ();
Signature · 7 lines
1.8.2.1 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 15/15 driver/scsi: Replace hardcoding of 20 with MIN_NICE.
In reply to Dongsheng Yang--- drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 4 ++-- drivers/scsi/bnx2i/bnx2i_hwi.c | 2 +- drivers/scsi/fcoe/fcoe.c | 2 +- drivers/scsi/ibmvscsi/ibmvfc.c | 2 +- drivers/scsi/ibmvscsi/ibmvscsi.c | 2 +- drivers/scsi/lpfc/lpfc_hbadisc.c | 2 +- drivers/scsi/qla2xxx/qla_os.c | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-)
drivers/scsi/bnx2fc/bnx2fc_fcoe.c +2 -2
@@ -464,7 +464,7 @@ static int bnx2fc_l2_rcv_thread(void *arg)struct fcoe_percpu_s *bg = arg;struct sk_buff *skb; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );set_current_state (TASK_INTERRUPTIBLE );while (!kthread_should_stop ()) {schedule ();
@@ -602,7 +602,7 @@ int bnx2fc_percpu_io_thread(void *arg)struct bnx2fc_work *work, *tmp;LIST_HEAD (work_list); -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );set_current_state (TASK_INTERRUPTIBLE );while (!kthread_should_stop ()) {schedule ();
drivers/scsi/bnx2i/bnx2i_hwi.c +1 -1
@@ -1870,7 +1870,7 @@ int bnx2i_percpu_io_thread(void *arg)struct bnx2i_work *work, *tmp;LIST_HEAD (work_list); -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );while (!kthread_should_stop ()) {spin_lock_bh (&p->p_work_lock);
drivers/scsi/fcoe/fcoe.c +1 -1
@@ -1872,7 +1872,7 @@ static int fcoe_percpu_receive_thread(void *arg)skb_queue_head_init (&tmp); -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE ); retry:while (!kthread_should_stop ()) {
drivers/scsi/ibmvscsi/ibmvfc.c +1 -1
@@ -4515,7 +4515,7 @@ static int ibmvfc_work(void *data)struct ibmvfc_host *vhost = data;int rc; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );while (1 ) { rc = wait_event_interruptible(vhost->work_wait_q,
drivers/scsi/ibmvscsi/ibmvscsi.c +1 -1
@@ -2213,7 +2213,7 @@ static int ibmvscsi_work(void *data)struct ibmvscsi_host_data *hostdata = data;int rc; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );while (1 ) { rc = wait_event_interruptible(hostdata->work_wait_q,
drivers/scsi/lpfc/lpfc_hbadisc.c +1 -1
@@ -733,7 +733,7 @@ lpfc_do_work(void *p)struct lpfc_hba *phba = p;int rc; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE ); current->flags |=PF_NOFREEZE ; phba->data_flags =0 ;
drivers/scsi/qla2xxx/qla_os.c +1 -1
@@ -4756,7 +4756,7 @@ qla2x00_do_dpc(void *data) ha = (struct qla_hw_data *)data; base_vha =pci_get_drvdata (ha->pdev); -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );set_current_state (TASK_INTERRUPTIBLE );while (!kthread_should_stop ()) {
Signature · 1 line
1.8.2.1
PATCH 2/15 kernel/sys: Replace opened code implementation with NICE_TO_RLIMIT macro.
In reply to Dongsheng YangFrom: Joe Perches <[email protected]>
Convert 20 - task_nice(p) to NICE_TO_RLIMIT(task_nice(p)).
Reduce the indent the switch case labels while there.
git diff -w shows 3 lines changed and a /* fall-through */ comment added
$ git diff -w -U0 kernel/sys.c @@ -253 +253 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) - niceval = 20 - task_nice(p); + niceval = NICE_TO_RLIMIT(task_nice(p)); @@ -264 +264 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) - niceval = 20 - task_nice(p); + niceval = NICE_TO_RLIMIT(task_nice(p)); @@ -280 +280 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who) - niceval = 20 - task_nice(p); + niceval = NICE_TO_RLIMIT(task_nice(p)); @@ -1558 +1558 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r) - + /* fall-through */
--- kernel/sys.c | 206 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 103 insertions(+), 103 deletions(-)
kernel/sys.c +103 -103
@@ -182,39 +182,39 @@ SYSCALL_DEFINE3(setpriority, int, which, int, who, int, niceval)rcu_read_lock ();read_lock (&tasklist_lock);switch (which) { -case PRIO_PROCESS : -if (who) - p =find_task_by_vpid (who); -else - p = current; -if (p) - error =set_one_prio (p, niceval, error); -break ; -case PRIO_PGRP : -if (who) - pgrp =find_vpid (who); -else - pgrp =task_pgrp (current); - do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { +case PRIO_PROCESS : +if (who) + p =find_task_by_vpid (who); +else + p = current; +if (p) + error =set_one_prio (p, niceval, error); +break ; +case PRIO_PGRP : +if (who) + pgrp =find_vpid (who); +else + pgrp =task_pgrp (current); + do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { + error =set_one_prio (p, niceval, error); + }while_each_pid_thread (pgrp,PIDTYPE_PGID , p); +break ; +case PRIO_USER : + uid =make_kuid (cred->user_ns, who); + user = cred->user; +if (!who) + uid = cred->uid; +else if (!uid_eq (uid, cred->uid) && + !(user =find_user (uid))) + goto out_unlock;/* No processes for this user */ + + do_each_thread(g, p) { +if (uid_eq (task_uid (p), uid)) error =set_one_prio (p, niceval, error); - }while_each_pid_thread (pgrp,PIDTYPE_PGID , p); -break ; -case PRIO_USER : - uid =make_kuid (cred->user_ns, who); - user = cred->user; -if (!who) - uid = cred->uid; -else if (!uid_eq (uid, cred->uid) && - !(user =find_user (uid))) - goto out_unlock;/* No processes for this user */ - - do_each_thread(g, p) { -if (uid_eq (task_uid (p), uid)) - error =set_one_prio (p, niceval, error); - }while_each_thread (g, p); -if (!uid_eq (uid, cred->uid)) -free_uid (user);/* For find_user() */ -break ; + }while_each_thread (g, p); +if (!uid_eq (uid, cred->uid)) +free_uid (user);/* For find_user() */ +break ; } out_unlock:read_unlock (&tasklist_lock);
@@ -244,47 +244,47 @@ SYSCALL_DEFINE2(getpriority, int, which, int, who)rcu_read_lock ();read_lock (&tasklist_lock);switch (which) { -case PRIO_PROCESS : -if (who) - p =find_task_by_vpid (who); -else - p = current; -if (p) { - niceval =20 -task_nice (p); +case PRIO_PROCESS : +if (who) + p =find_task_by_vpid (who); +else + p = current; +if (p) { + niceval =NICE_TO_RLIMIT (task_nice (p)); +if (niceval > retval) + retval = niceval; + } +break ; +case PRIO_PGRP : +if (who) + pgrp =find_vpid (who); +else + pgrp =task_pgrp (current); + do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { + niceval =NICE_TO_RLIMIT (task_nice (p)); +if (niceval > retval) + retval = niceval; + }while_each_pid_thread (pgrp,PIDTYPE_PGID , p); +break ; +case PRIO_USER : + uid =make_kuid (cred->user_ns, who); + user = cred->user; +if (!who) + uid = cred->uid; +else if (!uid_eq (uid, cred->uid) && + !(user =find_user (uid))) + goto out_unlock;/* No processes for this user */ + + do_each_thread(g, p) { +if (uid_eq (task_uid (p), uid)) { + niceval =NICE_TO_RLIMIT (task_nice (p));if (niceval > retval) retval = niceval; } -break ; -case PRIO_PGRP : -if (who) - pgrp =find_vpid (who); -else - pgrp =task_pgrp (current); - do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { - niceval =20 -task_nice (p); -if (niceval > retval) - retval = niceval; - }while_each_pid_thread (pgrp,PIDTYPE_PGID , p); -break ; -case PRIO_USER : - uid =make_kuid (cred->user_ns, who); - user = cred->user; -if (!who) - uid = cred->uid; -else if (!uid_eq (uid, cred->uid) && - !(user =find_user (uid))) - goto out_unlock;/* No processes for this user */ - - do_each_thread(g, p) { -if (uid_eq (task_uid (p), uid)) { - niceval =20 -task_nice (p); -if (niceval > retval) - retval = niceval; - } - }while_each_thread (g, p); -if (!uid_eq (uid, cred->uid)) -free_uid (user);/* for find_user() */ -break ; + }while_each_thread (g, p); +if (!uid_eq (uid, cred->uid)) +free_uid (user);/* for find_user() */ +break ; } out_unlock:read_unlock (&tasklist_lock);
@@ -1541,41 +1541,41 @@ static void k_getrusage(struct task_struct *p, int who, struct rusage *r)return ;switch (who) { -case RUSAGE_BOTH : -case RUSAGE_CHILDREN : - utime = p->signal->cutime; - stime = p->signal->cstime; - r->ru_nvcsw = p->signal->cnvcsw; - r->ru_nivcsw = p->signal->cnivcsw; - r->ru_minflt = p->signal->cmin_flt; - r->ru_majflt = p->signal->cmaj_flt; - r->ru_inblock = p->signal->cinblock; - r->ru_oublock = p->signal->coublock; - maxrss = p->signal->cmaxrss; - -if (who ==RUSAGE_CHILDREN ) -break ; - -case RUSAGE_SELF : -thread_group_cputime_adjusted (p, &tgutime, &tgstime); - utime += tgutime; - stime += tgstime; - r->ru_nvcsw += p->signal->nvcsw; - r->ru_nivcsw += p->signal->nivcsw; - r->ru_minflt += p->signal->min_flt; - r->ru_majflt += p->signal->maj_flt; - r->ru_inblock += p->signal->inblock; - r->ru_oublock += p->signal->oublock; -if (maxrss < p->signal->maxrss) - maxrss = p->signal->maxrss; - t = p; - do { - accumulate_thread_rusage(t, r); - } while_each_thread(p, t); +case RUSAGE_BOTH : +case RUSAGE_CHILDREN : + utime = p->signal->cutime; + stime = p->signal->cstime; + r->ru_nvcsw = p->signal->cnvcsw; + r->ru_nivcsw = p->signal->cnivcsw; + r->ru_minflt = p->signal->cmin_flt; + r->ru_majflt = p->signal->cmaj_flt; + r->ru_inblock = p->signal->cinblock; + r->ru_oublock = p->signal->coublock; + maxrss = p->signal->cmaxrss; + +if (who ==RUSAGE_CHILDREN )break ; +/* fall-through */ +case RUSAGE_SELF : +thread_group_cputime_adjusted (p, &tgutime, &tgstime); + utime += tgutime; + stime += tgstime; + r->ru_nvcsw += p->signal->nvcsw; + r->ru_nivcsw += p->signal->nivcsw; + r->ru_minflt += p->signal->min_flt; + r->ru_majflt += p->signal->maj_flt; + r->ru_inblock += p->signal->inblock; + r->ru_oublock += p->signal->oublock; +if (maxrss < p->signal->maxrss) + maxrss = p->signal->maxrss; + t = p; + do { + accumulate_thread_rusage(t, r); + } while_each_thread(p, t); + break; - default: - BUG(); + default: + BUG(); } unlock_task_sighand(p, &flags);
Signature · 1 line
1.8.2.1
PATCH 9/15 driver/block: Replace hardcoding of -20 with MIN_NICE.
In reply to Dongsheng Yang--- drivers/block/loop.c | 2 +- drivers/block/nbd.c | 2 +- drivers/block/pktcdvd.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/block/loop.c +1 -1
@@ -548,7 +548,7 @@ static int loop_thread(void *data)struct loop_device *lo = data;struct bio *bio; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );while (!kthread_should_stop () || !bio_list_empty (&lo->lo_bio_list)) {
drivers/block/nbd.c +1 -1
@@ -533,7 +533,7 @@ static int nbd_thread(void *data)struct nbd_device *nbd = data;struct request *req; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );while (!kthread_should_stop () || !list_empty (&nbd->waiting_queue)) {/* wait for something to do */ wait_event_interruptible(nbd->waiting_wq,
drivers/block/pktcdvd.c +1 -1
@@ -1463,7 +1463,7 @@ static int kcdrwd(void *foobar)struct packet_data *pkt;long min_sleep_time, residue; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE );set_freezable ();for (;;) {
Signature · 1 line
1.8.2.1
PATCH 12/15 driver/staging/android: Use RLIMIT_TO_NICE to replace opened code implementation.
In reply to Dongsheng YangThere is a macro RLINIT_TO_NICE in linux/sched/prio.h to convert priority in rlimit to nice value.
This patch replace the opened implementation with RLINIT_TO_NICE.
--- drivers/staging/android/binder.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/android/binder.c +2 -2
@@ -436,12 +436,12 @@ static void binder_set_nice(long nice)set_user_nice (current, nice);return ; } - min_nice =20 - current->signal->rlim[RLIMIT_NICE ].rlim_cur; + min_nice =RLIMIT_TO_NICE (current->signal->rlim[RLIMIT_NICE ].rlim_cur);binder_debug (BINDER_DEBUG_PRIORITY_CAP ,"%d: nice value %ld not allowed use %ld instead\n" , current->pid, nice, min_nice);set_user_nice (current, min_nice); -if (min_nice <20 ) +if (min_nice <=MAX_NICE )return ;binder_user_error ("%d RLIMIT_NICE not set\n" , current->pid); }
Signature · 1 line
1.8.2.1
PATCH 14/15 driver/staging/lustre: Replace hardcoding of -20 with MIN_NICE.
In reply to Dongsheng Yang--- drivers/staging/lustre/lustre/llite/lloop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/llite/lloop.c +1 -1
@@ -407,7 +407,7 @@ static int loop_thread(void *data)int refcheck;int ret =0 ; -set_user_nice (current,-20 ); +set_user_nice (current,MIN_NICE ); lo->lo_state =LLOOP_BOUND ;
Signature · 1 line
1.8.2.1
PATCH 10/15 driver/char: Replace hardcoding of 19 with MAX_NICE.
In reply to Dongsheng Yang--- drivers/char/ipmi/ipmi_si_intf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/ipmi/ipmi_si_intf.c +1 -1
@@ -999,7 +999,7 @@ static int ipmi_thread(void *data)struct timespec busy_until;ipmi_si_set_not_busy (&busy_until); -set_user_nice (current,19 ); +set_user_nice (current,MAX_NICE );while (!kthread_should_stop ()) {int busy_wait;
Signature · 1 line
1.8.2.1
PATCH 13/15 sched/prio: Add a macro named RLIMIT_TO_NICE in prio.h.
In reply to Dongsheng Yang--- include/linux/sched/prio.h | 1 + 1 file changed, 1 insertion(+)
include/linux/sched/prio.h +1 -0
@@ -45,5 +45,6 @@* Convert nice value [19,-20] to rlimit style value [1,40]. */ #define NICE_TO_RLIMIT (nice) (MAX_NICE - nice + 1) +#define RLIMIT_TO_NICE (prio) (MAX_NICE - prio + 1)#endif /* _SCHED_PRIO_H */
Signature · 1 line
1.8.2.1
PATCH 1/15 sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
In reply to Dongsheng YangThis patch add a macro named NICE_TO_RLIMIT in prio.h to convert nice value [19,-20] to rlimit style value [1,40].
--- include/linux/sched/prio.h | 5 +++++ 1 file changed, 5 insertions(+)
include/linux/sched/prio.h +5 -0
@@ -41,4 +41,9 @@#define TASK_USER_PRIO (p) USER_PRIO((p)->static_prio)#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) +/* +* Convert nice value [19,-20] to rlimit style value [1,40]. +*/ +#define NICE_TO_RLIMIT (nice) (MAX_NICE - nice + 1) +#endif /* _SCHED_PRIO_H */
Signature · 1 line
1.8.2.1
PATCH 7/15 ioprio: Add a macro named NICE_TO_IOPRIO.
In reply to Dongsheng YangAs the task nice value is in [-20, 19] and the io priority is in [0, 7], and the convert method from niceval to ioprio is implemented with an opened code in task_nice_ioprio().
This patch move the implementation to a macro NICE_TO_IOPRIO, making it more readable and modular.
--- include/linux/ioprio.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/linux/ioprio.h +6 -1
@@ -18,6 +18,11 @@#define ioprio_valid (mask) (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)/* +* Convert the nice value [19,-20] to io priority value [0,7]. +*/ +#define NICE_TO_IOPRIO (nice) (NICE_TO_RLIMIT(nice) / 5) + +/* * These are the io priority groups as implemented by CFQ. RT is the realtime * class, it always gets premium service. BE is the best-effort scheduling * class, the default for any process. IDLE is the idle scheduling class, it
@@ -52,7 +57,7 @@ enum {*/ static inline int task_nice_ioprio (struct task_struct *task) { -return (task_nice (task) +20 ) /5 ; +return NICE_TO_IOPRIO (task_nice (task)); }/*
Signature · 1 line
1.8.2.1
Re: [PATCH 01/15] sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
In reply to Dongsheng YangQuoted 13 lines · Dongsheng Yang
This patch add a macro named
NICE_TO_RLIMITinprio.hto convert nice value [19,-20] to rlimit style value [1,40].Signed-off-by Dongsheng Yang <[email protected]>--- include/linux/sched/prio.h | 5 +++++ 1 file changed, 5 insertions(+)include/linux/sched/prio.h +0
-0
include/linux/sched/prio.h line 47
Quoted 7 lines
include/linux/sched/prio.h +4
-0@@ -41,4 +41,9 @@#define TASK_USER_PRIO (p) USER_PRIO((p)->static_prio)#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) +/* +* Convert nice value [19,-20] to rlimit style value [1,40]. +*/ +#define NICE_TO_RLIMIT (nice) (MAX_NICE - nice + 1)
Where is MAX_NICE defined? The s390 patch fails to compile.
Also you probably want at least extra braces around the 'nice' usage to avoid subtle side effects. (or make NICE_TO.. a function, whatever).
Re: [PATCH 01/15] sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
Quoted 17 lines · Heiko Carstens
Quoted 16 lines · Dongsheng Yang
This patch add a macro named
NICE_TO_RLIMITinprio.hto convert nice value [19,-20] to rlimit style value [1,40].Signed-off-by Dongsheng Yang <[email protected]>--- include/linux/sched/prio.h | 5 +++++ 1 file changed, 5 insertions(+)include/linux/sched/prio.h +0
-0@@ -41,4 +41,9 @@#define TASK_USER_PRIO (p) USER_PRIO((p)->static_prio)#define MAX_USER_PRIO (USER_PRIO(MAX_PRIO))
Quoted 5 lines
include/linux/sched/prio.h line 47
Quoted 4 lines
include/linux/sched/prio.h +4
-0+/* +* Convert nice value [19,-20] to rlimit style value [1,40]. +*/ +#define NICE_TO_RLIMIT (nice) (MAX_NICE - nice + 1)Where is
MAX_NICEdefined? The s390 patch fails to compile.
MAX_NICE is defined in include/linux/sched/prio.h. It is applied in tip tree, and not in mainline yet.
Quoted 3 lines
Also you probably want at least extra braces around the 'nice' usage to avoid subtle side effects. (or make
NICE_TO.. a function, whatever).
Yes, agree. Another question is that I am not sure when I need to use a macro and when I should use a inline function.
Could you help to give me some sugguestion?
Thanx
Quoted 1 line
Re: [PATCH 01/15] sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
Quoted 7 lines · Dongsheng Yang
Quoted 3 lines · Heiko Carstens
Quoted 1 line · Dongsheng Yang
+#define
NICE_TO_RLIMIT(nice)(MAX_NICE- nice + 1)Where is
MAX_NICEdefined? The s390 patch fails to compile.
MAX_NICEis defined ininclude/linux/sched/prio.h. It is applied in tip tree, and not in mainline yet.
Ok.
Quoted 7 lines
Quoted 2 lines
Also you probably want at least extra braces around the 'nice' usage to avoid subtle side effects. (or make
NICE_TO.. a function, whatever).Yes, agree. Another question is that I am not sure when I need to use a macro and when I should use a inline function.
Could you help to give me some sugguestion?
You can ask three people and get five opinions ;)
However if your above define would have been an inline function it wouldn't suffer from possible subtle side effects and it would have sane type checking etc. So usually functions should be preferred.
Re: [PATCH 01/15] sched/prio: Add a macro named NICE_TO_RLIMIT in prio.h.
Quoted 9 lines · Heiko Carstens
Quoted 6 lines · Dongsheng Yang
Quoted 3 lines · Heiko Carstens
Quoted 1 line · Dongsheng Yang
+#define
NICE_TO_RLIMIT(nice)(MAX_NICE- nice + 1)Where is
MAX_NICEdefined? The s390 patch fails to compile.
MAX_NICEis defined ininclude/linux/sched/prio.h. It is applied in tip tree, and not in mainline yet.Ok.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Also you probably want at least extra braces around the 'nice' usage to avoid subtle side effects. (or make
NICE_TO.. a function, whatever).Yes, agree. Another question is that I am not sure when I need to use a macro and when I should use a inline function.
Could you help to give me some sugguestion?
You can ask three people and get five opinions ;)
Hehe :)
Quoted 4 lines
However if your above define would have been an inline function it wouldn't suffer from possible subtle side effects and it would have sane type checking etc. So usually functions should be preferred.
I prefer to inline function too, it makes me feel more safe.
I will update this patch with an inline function.
Thanx