Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Apr 2019 15:56:06 -0700
From:      Mark Millard <marklmi@yahoo.com>
To:        FreeBSD PowerPC ML <freebsd-ppc@freebsd.org>, Justin Hibbits <chmeeedalf@gmail.com>
Subject:   spinlock_enter, head -r346144 (and before) and use of nop_prio_mhigh vs. PowerISA document suggestions for lock code
Message-ID:  <F0A58D08-4A99-4483-A419-200A1485E73E@yahoo.com>

next in thread | raw e-mail | index | archive | help
I found the following text in each of the 2.03, 2.04, 2.05,
2.06B V2, 2.07, and 3.0B PowerISA documents, in a "Programming
Note" in the "Program Priority Registers" section:

". . . if a program is waiting on a lock (...), it could set low =
priority with the
result that more processor resources would be diverted to the program =
that holds the
lock. This diversion of resources may enable the lock-holding program to =
complete
the operation under the lock more quickly, and then relinquish the lock =
to the waiting
program."

The wording suggests working via normal/medium and lower
priorities instead of via normal/medium and higher priorities.
(May be more than just the relative priority matters in the
behavior changes that result each way? Unfortunately the
wording is not very explicit.)

All of the documents list "or rx,rx,rx" for:
Rx being 31 or 1 or 6 or 2 or 5 or 3 or 7
(listed lowest to highest relative priority),
2 being normal/medium. Some table(s) might not
list 3 or 7 in a document but at least one does
in each.

In the following powerpc64 and 32-bit powerpc
FreeBSD seem to be going in the opposite direction
relative to normal/medium vs. the suggestion
of "low priority":

void
spinlock_enter(void)
{
	struct thread *td;
	register_t msr;

	td =3D curthread;
	if (td->td_md.md_spinlock_count =3D=3D 0) {
		nop_prio_mhigh();
		msr =3D intr_disable();
		td->td_md.md_spinlock_count =3D 1;
		td->td_md.md_saved_msr =3D msr;
	} else
		td->td_md.md_spinlock_count++;
	critical_enter();
}

void
spinlock_exit(void)
{
	struct thread *td;
	register_t msr;

	td =3D curthread;
	critical_exit();
	msr =3D td->td_md.md_saved_msr;
	td->td_md.md_spinlock_count--;
	if (td->td_md.md_spinlock_count =3D=3D 0) {
		intr_restore(msr);
		nop_prio_medium();
	}
}

and previously:

void
spinlock_enter(void)
{
        struct thread *td;
        register_t msr;
=20
        td =3D curthread;
        if (td->td_md.md_spinlock_count =3D=3D 0) {
                __asm __volatile("or 2,2,2"); /* Set high thread =
priority */
                msr =3D intr_disable();
                td->td_md.md_spinlock_count =3D 1;
                td->td_md.md_saved_msr =3D msr;
        } else
                td->td_md.md_spinlock_count++;
        critical_enter();
}

void
spinlock_exit(void)
{
        struct thread *td;
        register_t msr;

        td =3D curthread;
        critical_exit();
        msr =3D td->td_md.md_saved_msr;
        td->td_md.md_spinlock_count--;
        if (td->td_md.md_spinlock_count =3D=3D 0) {
                intr_restore(msr);
                __asm __volatile("or 6,6,6"); /* Set normal thread =
priority */
        }
}

(2,2,2 was higher then 6,6,6 but 2,2,2 is
normal/medium and 6,6,6 is "medium low" the
way the PowerISA documentation reads.)

2.06B V2 and 2.07 also list special meanings for:
27 and 29 and 30. (cpu_spinwait in FreeBSD uses 27.)
But 3.0B does not list them any more.

2.07 and 3.0B lists a special meaning for: 26.
No prior version that I looked at does.



=3D=3D=3D
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?F0A58D08-4A99-4483-A419-200A1485E73E>