From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <89a44511b98911d8e26633895373dab7@hamnavoe.com> References: <1092190499.1253166.1522781548163@mail.yahoo.com> <89a44511b98911d8e26633895373dab7@hamnavoe.com> From: Skip Tavakkolian Date: Tue, 3 Apr 2018 17:30:24 -0700 Message-ID: To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary="000000000000e2ee980568faedbd" Subject: Re: [9fans] Plan9 on Pi 3B+ Topicbox-Message-UUID: d37f23b6-ead9-11e9-9d60-3106f5b1d025 --000000000000e2ee980568faedbd Content-Type: text/plain; charset="UTF-8" Thanks! I got one recently and have been meaning to ask about his. Running Linux, 3B+ seems perceptibly faster than 3B. On Tue, Apr 3, 2018 at 2:05 PM, Richard Miller <9fans@hamnavoe.com> wrote: > > But what is the > > rationale for the lock in the second loop? > > Sorry for the confusing code. The startlocks are locked by > cpu0 before booting the secondary cores. Each core unlocks > its own startlock when it starts. Cpu0 blocks on each startlock > waiting for the corresponding core to unlock it, as a way of > serialising the booting of the secondary cores (and detecting > that they have started). > > If for some reason the secondary cpus don't start up, the > result is a lock loop. I really should have used canlock() > instead, to expose a more helpful error message. But it's > a "should never happen" condition. > > It's happening with the new start_cd.elf because the Pi > Foundation made a little change in the firmware which makes > secondary cores wait with a WFE when booting, so the OS > now has to do a SEV to wake them up. > > I'm just about to release an update to the bcm port for > the 3B+, including drivers for the new "gigabit" ethernet > (not really, because it's squeezed through a slow usb2 adapter) > and the updated wifi chip. But in the meantime the following > should let you boot any pi2 or pi3 with the latest start_cd.elf: > > --- /sys/src/9/bcm/archbcm2.c Fri Mar 16 17:08:21 2018 > *************** > *** 167,172 **** > --- 167,174 ---- > if(mb->clr[cpu].startcpu) > return -1; > mb->set[cpu].startcpu = PADDR(cpureset); > + coherence(); > + sev(); > for(i = 0; i < 1000; i++) > if(mb->clr[cpu].startcpu == 0) > return 0; > *************** > *** 196,202 **** > int > startcpus(uint ncpu) > { > ! int i; > > for(i = 0; i < ncpu; i++) > lock(&startlock[i]); > --- 198,204 ---- > int > startcpus(uint ncpu) > { > ! int i, timeout; > > for(i = 0; i < ncpu; i++) > lock(&startlock[i]); > *************** > *** 204,210 **** > for(i = 1; i < ncpu; i++){ > if(startcpu(i) < 0) > return i; > ! lock(&startlock[i]); > unlock(&startlock[i]); > } > return ncpu; > --- 206,215 ---- > for(i = 1; i < ncpu; i++){ > if(startcpu(i) < 0) > return i; > ! timeout = 10000000; > ! while(!canlock(&startlock[i])) > ! if(--timeout == 0) > ! return i; > unlock(&startlock[i]); > } > return ncpu; > > --- /sys/src/9/bcm/armv7.s Fri Mar 16 16:47:18 2018 > *************** > *** 17,22 **** > --- 17,23 ---- > #define WFI WORD $0xe320f003 /* wait for interrupt */ > #define WFI_EQ WORD $0x0320f003 /* wait for interrupt if > eq */ > #define ERET WORD $0xe160006e /* exception return from HYP */ > + #define SEV WORD $0xe320f004 /* send event */ > > /* tas/cas strex debugging limits; started at 10000 */ > #define MAXSC 1000000 > *************** > *** 386,391 **** > --- 387,396 ---- > > TEXT coherence(SB), $-4 > BARRIERS > + RET > + > + TEXT sev(SB), $-4 > + SEV > RET > > /* > > > --000000000000e2ee980568faedbd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks!=C2=A0 =C2=A0I got one recently and have been meani= ng to ask about his.

Running Linux, 3B+ seems perceptibl= y faster than 3B.=C2=A0

On Tue, Apr 3, 2018 at 2:05 PM, Richard Miller <9fans@= hamnavoe.com> wrote:
> But what is the
> rationale for the lock in the second loop?

Sorry for the confusing code.=C2=A0 The startlocks are locked by
cpu0 before booting the secondary cores.=C2=A0 Each core unlocks
its own startlock when it starts.=C2=A0 Cpu0 blocks on each startlock
waiting for the corresponding core to unlock it, as a way of
serialising the booting of the secondary cores (and detecting
that they have started).

If for some reason the secondary cpus don't start up, the
result is a lock loop.=C2=A0 I really should have used canlock()
instead, to expose a more helpful error message.=C2=A0 But it's
a "should never happen" condition.

It's happening with the new start_cd.elf because the Pi
Foundation made a little change in the firmware which makes
secondary cores wait with a WFE when booting, so the OS
now has to do a SEV to wake them up.

I'm just about to release an update to the bcm port for
the 3B+, including drivers for the new "gigabit" ethernet
(not really, because it's squeezed through a slow usb2 adapter)
and the updated wifi chip.=C2=A0 But in the meantime the following
should let you boot any pi2 or pi3 with the latest start_cd.elf:

--- /sys/src/9/bcm/archbcm2.c=C2=A0 =C2=A0Fri Mar 16 17:08:21 2018
***************
*** 167,172 ****
--- 167,174 ----
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if(mb->clr[cpu].startcpu)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -1;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 mb->set[cpu].startcpu =3D PADDR(cpureset); +=C2=A0 =C2=A0 =C2=A0 =C2=A0coherence();
+=C2=A0 =C2=A0 =C2=A0 =C2=A0sev();
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for(i =3D 0; i < 1000; i++)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if(mb->clr[cpu].= startcpu =3D=3D 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return 0;
***************
*** 196,202 ****
=C2=A0 int
=C2=A0 startcpus(uint ncpu)
=C2=A0 {
!=C2=A0 =C2=A0 =C2=A0 =C2=A0int i;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 for(i =3D 0; i < ncpu; i++)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 lock(&startlock= [i]);
--- 198,204 ----
=C2=A0 int
=C2=A0 startcpus(uint ncpu)
=C2=A0 {
!=C2=A0 =C2=A0 =C2=A0 =C2=A0int i, timeout;

=C2=A0 =C2=A0 =C2=A0 =C2=A0 for(i =3D 0; i < ncpu; i++)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 lock(&startlock= [i]);
***************
*** 204,210 ****
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for(i =3D 1; i < ncpu; i++)= {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if(startcpu(i) <= 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return i;
!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0lock(&st= artlock[i]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unlock(&startlo= ck[i]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ncpu;
--- 206,215 ----
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for(i =3D 1; i < ncpu; i++)= {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if(startcpu(i) <= 0)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 return i;
!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0timeout =3D = 10000000;
!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0while(!canlock(&= ;startlock[i]))
!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0if(--timeout =3D=3D 0)
!=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return i;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unlock(&startlo= ck[i]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return ncpu;

--- /sys/src/9/bcm/armv7.s=C2=A0 =C2=A0 =C2=A0 Fri Mar 16 16:47:18 2018
***************
*** 17,22 ****
--- 17,23 ----
=C2=A0 #define WFI=C2=A0 =C2=A0WORD=C2=A0 =C2=A0 $0xe320f003=C2=A0 =C2=A0 = =C2=A0/* wait for interrupt */
=C2=A0 #define WFI_EQ=C2=A0 =C2=A0 =C2=A0 =C2=A0 WORD=C2=A0 =C2=A0 $0x0320f= 003=C2=A0 =C2=A0 =C2=A0/* wait for interrupt if eq */
=C2=A0 #define ERET=C2=A0 WORD=C2=A0 =C2=A0 $0xe160006e=C2=A0 =C2=A0 =C2=A0= /* exception return from HYP */
+ #define SEV=C2=A0 =C2=A0WORD=C2=A0 =C2=A0 $0xe320f004=C2=A0 =C2=A0 =C2=A0= /* send event */

=C2=A0 /* tas/cas strex debugging limits; started at 10000 */
=C2=A0 #define MAXSC 1000000
***************
*** 386,391 ****
--- 387,396 ----

=C2=A0 TEXT coherence(SB), $-4
=C2=A0 =C2=A0 =C2=A0 =C2=A0 BARRIERS
+=C2=A0 =C2=A0 =C2=A0 =C2=A0RET
+
+ TEXT sev(SB), $-4
+=C2=A0 =C2=A0 =C2=A0 =C2=A0SEV
=C2=A0 =C2=A0 =C2=A0 =C2=A0 RET

=C2=A0 /*



--000000000000e2ee980568faedbd--