@@ -402,9 +402,9 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
402402 poll_table * wait ;
403403 int retval , i , timed_out = 0 ;
404404 unsigned long slack = 0 ;
405- unsigned int ll_flag = ll_get_flag () ;
406- u64 ll_start = ll_start_time ( ll_flag );
407- u64 ll_time = ll_run_time ();
405+ unsigned int busy_flag = net_busy_loop_on () ? POLL_BUSY_LOOP : 0 ;
406+ u64 busy_start = busy_loop_start_time ( busy_flag );
407+ u64 busy_end = busy_loop_end_time ();
408408
409409 rcu_read_lock ();
410410 retval = max_select_fd (n , fds );
@@ -427,7 +427,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
427427 retval = 0 ;
428428 for (;;) {
429429 unsigned long * rinp , * routp , * rexp , * inp , * outp , * exp ;
430- bool can_ll = false;
430+ bool can_busy_loop = false;
431431
432432 inp = fds -> in ; outp = fds -> out ; exp = fds -> ex ;
433433 rinp = fds -> res_in ; routp = fds -> res_out ; rexp = fds -> res_ex ;
@@ -456,7 +456,7 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
456456 mask = DEFAULT_POLLMASK ;
457457 if (f_op && f_op -> poll ) {
458458 wait_key_set (wait , in , out ,
459- bit , ll_flag );
459+ bit , busy_flag );
460460 mask = (* f_op -> poll )(f .file , wait );
461461 }
462462 fdput (f );
@@ -475,11 +475,18 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
475475 retval ++ ;
476476 wait -> _qproc = NULL ;
477477 }
478- if (mask & POLL_LL )
479- can_ll = true;
480478 /* got something, stop busy polling */
481- if (retval )
482- ll_flag = 0 ;
479+ if (retval ) {
480+ can_busy_loop = false;
481+ busy_flag = 0 ;
482+
483+ /*
484+ * only remember a returned
485+ * POLL_BUSY_LOOP if we asked for it
486+ */
487+ } else if (busy_flag & mask )
488+ can_busy_loop = true;
489+
483490 }
484491 }
485492 if (res_in )
@@ -498,8 +505,9 @@ int do_select(int n, fd_set_bits *fds, struct timespec *end_time)
498505 break ;
499506 }
500507
501- /* only if on, have sockets with POLL_LL and not out of time */
502- if (ll_flag && can_ll && can_poll_ll (ll_start , ll_time ))
508+ /* only if found POLL_BUSY_LOOP sockets && not out of time */
509+ if (!need_resched () && can_busy_loop &&
510+ busy_loop_range (busy_start , busy_end ))
503511 continue ;
504512
505513 /*
@@ -734,7 +742,8 @@ struct poll_list {
734742 * if pwait->_qproc is non-NULL.
735743 */
736744static inline unsigned int do_pollfd (struct pollfd * pollfd , poll_table * pwait ,
737- bool * can_ll , unsigned int ll_flag )
745+ bool * can_busy_poll ,
746+ unsigned int busy_flag )
738747{
739748 unsigned int mask ;
740749 int fd ;
@@ -748,10 +757,10 @@ static inline unsigned int do_pollfd(struct pollfd *pollfd, poll_table *pwait,
748757 mask = DEFAULT_POLLMASK ;
749758 if (f .file -> f_op && f .file -> f_op -> poll ) {
750759 pwait -> _key = pollfd -> events |POLLERR |POLLHUP ;
751- pwait -> _key |= ll_flag ;
760+ pwait -> _key |= busy_flag ;
752761 mask = f .file -> f_op -> poll (f .file , pwait );
753- if (mask & POLL_LL )
754- * can_ll = true;
762+ if (mask & busy_flag )
763+ * can_busy_poll = true;
755764 }
756765 /* Mask out unneeded events. */
757766 mask &= pollfd -> events | POLLERR | POLLHUP ;
@@ -770,9 +779,10 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
770779 ktime_t expire , * to = NULL ;
771780 int timed_out = 0 , count = 0 ;
772781 unsigned long slack = 0 ;
773- unsigned int ll_flag = ll_get_flag ();
774- u64 ll_start = ll_start_time (ll_flag );
775- u64 ll_time = ll_run_time ();
782+ unsigned int busy_flag = net_busy_loop_on () ? POLL_BUSY_LOOP : 0 ;
783+ u64 busy_start = busy_loop_start_time (busy_flag );
784+ u64 busy_end = busy_loop_end_time ();
785+
776786
777787 /* Optimise the no-wait case */
778788 if (end_time && !end_time -> tv_sec && !end_time -> tv_nsec ) {
@@ -785,7 +795,7 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
785795
786796 for (;;) {
787797 struct poll_list * walk ;
788- bool can_ll = false;
798+ bool can_busy_loop = false;
789799
790800 for (walk = list ; walk != NULL ; walk = walk -> next ) {
791801 struct pollfd * pfd , * pfd_end ;
@@ -800,10 +810,13 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
800810 * this. They'll get immediately deregistered
801811 * when we break out and return.
802812 */
803- if (do_pollfd (pfd , pt , & can_ll , ll_flag )) {
813+ if (do_pollfd (pfd , pt , & can_busy_loop ,
814+ busy_flag )) {
804815 count ++ ;
805816 pt -> _qproc = NULL ;
806- ll_flag = 0 ;
817+ /* found something, stop busy polling */
818+ busy_flag = 0 ;
819+ can_busy_loop = false;
807820 }
808821 }
809822 }
@@ -820,8 +833,9 @@ static int do_poll(unsigned int nfds, struct poll_list *list,
820833 if (count || timed_out )
821834 break ;
822835
823- /* only if on, have sockets with POLL_LL and not out of time */
824- if (ll_flag && can_ll && can_poll_ll (ll_start , ll_time ))
836+ /* only if found POLL_BUSY_LOOP sockets && not out of time */
837+ if (!need_resched () && can_busy_loop &&
838+ busy_loop_range (busy_start , busy_end ))
825839 continue ;
826840
827841 /*
0 commit comments