ice: sleep, don't busy-wait, for ICE_CTL_Q_SQ_CMD_TIMEOUT
authorMichal Schmidt <mschmidt@redhat.com>
Wed, 12 Apr 2023 08:19:27 +0000 (10:19 +0200)
committerTony Nguyen <anthony.l.nguyen@intel.com>
Thu, 20 Apr 2023 23:33:14 +0000 (16:33 -0700)
The driver polls for ice_sq_done() with a 100 µs period for up to 1 s
and it uses udelay to do that.

Let's use usleep_range instead. We know sleeping is allowed here,
because we're holding a mutex (cq->sq_lock). To preserve the total
max waiting time, measure the timeout in jiffies.

ICE_CTL_Q_SQ_CMD_TIMEOUT is used also in ice_release_res(), but there
the polling period is 1 ms (i.e. 10 times longer). Since the timeout was
expressed in terms of the number of loops, the total timeout in this
function is 10 s. I do not know if this is intentional. This patch keeps
it.

The patch lowers the CPU usage of the ice-gnss-<dev_name> kernel thread
on my system from ~8 % to less than 1 %.

I received a report of high CPU usage with ptp4l where the busy-waiting
in ice_sq_send_cmd dominated the profile. This patch has been tested in
that usecase too and it made a huge improvement there.

Tested-by: Brent Rowsell <browsell@redhat.com>
Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
Reviewed-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Tested-by: Sunitha Mekala <sunithax.d.mekala@intel.com> (A Contingent worker at Intel)
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
drivers/net/ethernet/intel/ice/ice_common.c
drivers/net/ethernet/intel/ice/ice_controlq.c
drivers/net/ethernet/intel/ice/ice_controlq.h

index f4c256563248f8442d1b8c4105be7b97a089a388..3638598d732b411968c513ab1913e2be0045e406 100644 (file)
@@ -1992,19 +1992,19 @@ ice_acquire_res_exit:
  */
 void ice_release_res(struct ice_hw *hw, enum ice_aq_res_ids res)
 {
-       u32 total_delay = 0;
+       unsigned long timeout;
        int status;
 
-       status = ice_aq_release_res(hw, res, 0, NULL);
-
        /* there are some rare cases when trying to release the resource
         * results in an admin queue timeout, so handle them correctly
         */
-       while ((status == -EIO) && (total_delay < ICE_CTL_Q_SQ_CMD_TIMEOUT)) {
-               mdelay(1);
+       timeout = jiffies + 10 * ICE_CTL_Q_SQ_CMD_TIMEOUT;
+       do {
                status = ice_aq_release_res(hw, res, 0, NULL);
-               total_delay++;
-       }
+               if (status != -EIO)
+                       break;
+               usleep_range(1000, 2000);
+       } while (time_before(jiffies, timeout));
 }
 
 /**
index c8fb10106ec3b4cb717c08a441779e5adc1bb4ea..d2faf1baad2f9d14b4d01a30fff2d8fc11a09775 100644 (file)
@@ -964,7 +964,7 @@ ice_sq_send_cmd(struct ice_hw *hw, struct ice_ctl_q_info *cq,
        struct ice_aq_desc *desc_on_ring;
        bool cmd_completed = false;
        struct ice_sq_cd *details;
-       u32 total_delay = 0;
+       unsigned long timeout;
        int status = 0;
        u16 retval = 0;
        u32 val = 0;
@@ -1057,13 +1057,14 @@ ice_sq_send_cmd(struct ice_hw *hw, struct ice_ctl_q_info *cq,
                cq->sq.next_to_use = 0;
        wr32(hw, cq->sq.tail, cq->sq.next_to_use);
 
+       timeout = jiffies + ICE_CTL_Q_SQ_CMD_TIMEOUT;
        do {
                if (ice_sq_done(hw, cq))
                        break;
 
-               udelay(ICE_CTL_Q_SQ_CMD_USEC);
-               total_delay++;
-       } while (total_delay < ICE_CTL_Q_SQ_CMD_TIMEOUT);
+               usleep_range(ICE_CTL_Q_SQ_CMD_USEC,
+                            ICE_CTL_Q_SQ_CMD_USEC * 3 / 2);
+       } while (time_before(jiffies, timeout));
 
        /* if ready, copy the desc back to temp */
        if (ice_sq_done(hw, cq)) {
index e790b2f4e437a94b5e55e07b7ae320491508bd9b..950b7f4a7a053df7f6a098efd8c8790bb3625c28 100644 (file)
@@ -34,7 +34,7 @@ enum ice_ctl_q {
 };
 
 /* Control Queue timeout settings - max delay 1s */
-#define ICE_CTL_Q_SQ_CMD_TIMEOUT       10000 /* Count 10000 times */
+#define ICE_CTL_Q_SQ_CMD_TIMEOUT       HZ    /* Wait max 1s */
 #define ICE_CTL_Q_SQ_CMD_USEC          100   /* Check every 100usec */
 #define ICE_CTL_Q_ADMIN_INIT_TIMEOUT   10    /* Count 10 times */
 #define ICE_CTL_Q_ADMIN_INIT_MSEC      100   /* Check every 100msec */