Re: misc. acpi(4): *sleep -> *sleep_nsec(9)

2019-11-25 Thread Paul Irofti
On Fri, Nov 22, 2019 at 06:08:34PM -0600, Scott Cheloha wrote:
> The acpi_event_wait() loop is tricky.  I'm leaving it alone for now.
> 
> Everything else here is straightforward, though.  The acpiec(4) sleep
> is adjacent to a delay of 1 microsecond so I've chosen that to replace
> the current duration of 1 tick.
> 
> ok?

I am very uneasy when I see this sort of diffs in acpi(4). We fought
sleeping bugs and lost a lot of hair about these sort of primitives when
we did suspend/resume.

I really appreciate the work you are doing towards removing hz, but
for our comfort at least, could you provide us with a bit more
explanations and ask for thorough testing before switching?

Thanks,
Paul

> 
> Index: acpi.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
> retrieving revision 1.374
> diff -u -p -r1.374 acpi.c
> --- acpi.c7 Sep 2019 13:46:20 -   1.374
> +++ acpi.c23 Nov 2019 00:02:15 -
> @@ -2866,9 +2866,7 @@ acpi_thread(void *arg)
>   s = spltty();
>   while (sc->sc_threadwaiting) {
>   dnprintf(10, "acpi thread going to sleep...\n");
> - rw_exit_write(>sc_lck);
> - tsleep(sc, PWAIT, "acpi0", 0);
> - rw_enter_write(>sc_lck);
> + rwsleep_nsec(sc, >sc_lck, PWAIT, "acpi0", INFSLP);
>   }
>   sc->sc_threadwaiting = 1;
>   splx(s);
> Index: acpiec.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/acpiec.c,v
> retrieving revision 1.60
> diff -u -p -r1.60 acpiec.c
> --- acpiec.c  2 Jul 2019 21:17:24 -   1.60
> +++ acpiec.c  23 Nov 2019 00:02:16 -
> @@ -107,8 +107,10 @@ acpiec_wait(struct acpiec_softc *sc, uin
>   sc->sc_gotsci = 1;
>   if (cold || (stat & EC_STAT_BURST))
>   delay(1);
> - else
> - tsleep(, PWAIT, "acpiec", 1);
> + else {
> + tsleep_nsec(, PWAIT, "acpiec",
> + USEC_TO_NSEC(1));
> + }
>   }
>  
>   dnprintf(40, "%s: EC wait_ns, stat: %b\n", DEVNAME(sc), (int)stat,
> Index: dsdt.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
> retrieving revision 1.249
> diff -u -p -r1.249 dsdt.c
> --- dsdt.c16 Oct 2019 01:43:50 -  1.249
> +++ dsdt.c23 Nov 2019 00:02:16 -
> @@ -465,15 +465,11 @@ void
>  acpi_sleep(int ms, char *reason)
>  {
>   static int acpinowait;
> - int to = ms * hz / 1000;
>  
>   if (cold)
>   delay(ms * 1000);
> - else {
> - if (to <= 0)
> - to = 1;
> - tsleep(, PWAIT, reason, to);
> - }
> + else
> + tsleep_nsec(, PWAIT, reason, MSEC_TO_NSEC(ms));
>  }
>  
>  void
> Index: tipmic.c
> ===
> RCS file: /cvs/src/sys/dev/acpi/tipmic.c,v
> retrieving revision 1.4
> diff -u -p -r1.4 tipmic.c
> --- tipmic.c  4 Apr 2019 06:33:10 -   1.4
> +++ tipmic.c  23 Nov 2019 00:02:16 -
> @@ -333,7 +333,8 @@ tipmic_thermal_opreg_handler(void *cooki
>   splx(s);
>  
>   while (sc->sc_stat_adc == 0) {
> - if (tsleep(>sc_stat_adc, PRIBIO, "tipmic", hz)) {
> + if (tsleep_nsec(>sc_stat_adc, PRIBIO, "tipmic",
> + SEC_TO_NSEC(1))) {
>   printf("%s: ADC timeout\n", sc->sc_dev.dv_xname);
>   break;
>   }



misc. acpi(4): *sleep -> *sleep_nsec(9)

2019-11-22 Thread Scott Cheloha
The acpi_event_wait() loop is tricky.  I'm leaving it alone for now.

Everything else here is straightforward, though.  The acpiec(4) sleep
is adjacent to a delay of 1 microsecond so I've chosen that to replace
the current duration of 1 tick.

ok?

Index: acpi.c
===
RCS file: /cvs/src/sys/dev/acpi/acpi.c,v
retrieving revision 1.374
diff -u -p -r1.374 acpi.c
--- acpi.c  7 Sep 2019 13:46:20 -   1.374
+++ acpi.c  23 Nov 2019 00:02:15 -
@@ -2866,9 +2866,7 @@ acpi_thread(void *arg)
s = spltty();
while (sc->sc_threadwaiting) {
dnprintf(10, "acpi thread going to sleep...\n");
-   rw_exit_write(>sc_lck);
-   tsleep(sc, PWAIT, "acpi0", 0);
-   rw_enter_write(>sc_lck);
+   rwsleep_nsec(sc, >sc_lck, PWAIT, "acpi0", INFSLP);
}
sc->sc_threadwaiting = 1;
splx(s);
Index: acpiec.c
===
RCS file: /cvs/src/sys/dev/acpi/acpiec.c,v
retrieving revision 1.60
diff -u -p -r1.60 acpiec.c
--- acpiec.c2 Jul 2019 21:17:24 -   1.60
+++ acpiec.c23 Nov 2019 00:02:16 -
@@ -107,8 +107,10 @@ acpiec_wait(struct acpiec_softc *sc, uin
sc->sc_gotsci = 1;
if (cold || (stat & EC_STAT_BURST))
delay(1);
-   else
-   tsleep(, PWAIT, "acpiec", 1);
+   else {
+   tsleep_nsec(, PWAIT, "acpiec",
+   USEC_TO_NSEC(1));
+   }
}
 
dnprintf(40, "%s: EC wait_ns, stat: %b\n", DEVNAME(sc), (int)stat,
Index: dsdt.c
===
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.249
diff -u -p -r1.249 dsdt.c
--- dsdt.c  16 Oct 2019 01:43:50 -  1.249
+++ dsdt.c  23 Nov 2019 00:02:16 -
@@ -465,15 +465,11 @@ void
 acpi_sleep(int ms, char *reason)
 {
static int acpinowait;
-   int to = ms * hz / 1000;
 
if (cold)
delay(ms * 1000);
-   else {
-   if (to <= 0)
-   to = 1;
-   tsleep(, PWAIT, reason, to);
-   }
+   else
+   tsleep_nsec(, PWAIT, reason, MSEC_TO_NSEC(ms));
 }
 
 void
Index: tipmic.c
===
RCS file: /cvs/src/sys/dev/acpi/tipmic.c,v
retrieving revision 1.4
diff -u -p -r1.4 tipmic.c
--- tipmic.c4 Apr 2019 06:33:10 -   1.4
+++ tipmic.c23 Nov 2019 00:02:16 -
@@ -333,7 +333,8 @@ tipmic_thermal_opreg_handler(void *cooki
splx(s);
 
while (sc->sc_stat_adc == 0) {
-   if (tsleep(>sc_stat_adc, PRIBIO, "tipmic", hz)) {
+   if (tsleep_nsec(>sc_stat_adc, PRIBIO, "tipmic",
+   SEC_TO_NSEC(1))) {
printf("%s: ADC timeout\n", sc->sc_dev.dv_xname);
break;
}