Bug in ksched_setscheduler?

Dmitry Krivenok krivenok.dmitry at gmail.com
Wed Jun 1 16:42:44 UTC 2011


Hello Hackers,
I think I found a bug in ksched_setscheduler() function.

178 int
179 ksched_setscheduler(struct ksched *ksched,
180     struct thread *td, int policy, const struct sched_param *param)
181 {
182         int e = 0;
183         struct rtprio rtp;
184
185         switch(policy)
186         {
187                 case SCHED_RR:
188                 case SCHED_FIFO:
189
190                 if (param->sched_priority >= P1B_PRIO_MIN &&
191                     param->sched_priority <= P1B_PRIO_MAX)
192                 {
193                         rtp.prio = p4prio_to_rtpprio(param->sched_priority);
194                         rtp.type = (policy == SCHED_FIFO)
195                                 ? RTP_PRIO_FIFO : RTP_PRIO_REALTIME;
196
197                         rtp_to_pri(&rtp, td);
198                 }
199                 else
200                         e = EPERM;
201
202
203                 break;
204
205                 case SCHED_OTHER:
206                 if (param->sched_priority >= 0 &&
207                         param->sched_priority <=
(PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE)) {
208                         rtp.type = RTP_PRIO_NORMAL;
209                         rtp.prio = p4prio_to_rtpprio(param->sched_priority);
210                         rtp_to_pri(&rtp, td);
211                 } else
212                         e = EINVAL;
213
214                 break;
215
216                 default:
217                         e = EINVAL;
218                         break;
219         }
220
221         return e;
222 }

Shouldn't we use p4prio_to_tsprio instead of p4prio_to_rtpprio at the line 209?
This macro is defined but never used in kernel code:

$ grep -r 'p4prio_to_tsprio' /usr/src/sys/
/usr/src/sys/kern/ksched.c:#define p4prio_to_tsprio(P)
((PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE) - (P))
$

Is it a real bug or just my misunderstanding of something?

Thanks!

-- 
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmitry at gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmitry at jabber.ru
icq: 242-526-443


More information about the freebsd-hackers mailing list