Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Oct 2011 15:27:28 -0700
From:      Juli Mallett <jmallett@FreeBSD.org>
To:        Rohit J <mipsjunkie@gmail.com>
Cc:        Oleksandr Tymoshenko <gonzo@freebsd.org>, freebsd-mips <freebsd-mips@freebsd.org>
Subject:   Re: Assembler complains about use of $at after ".set noat" on sd instr
Message-ID:  <CACVs6=9mKLreStSFgxqJ3eybPPX2ikMTx=7djjth6Bo_P52R4w@mail.gmail.com>
In-Reply-To: <CAPJ9Q0W4MggQ-BumAkNRXpR618JZPESyUWbLw8porD-J0ayeXQ@mail.gmail.com>
References:  <CAPJ9Q0U%2BJ9U46XuAAi0p7X0wkDazRRN5aUKgpFYU7bPCEj_H5A@mail.gmail.com> <CACVs6=8F=QfEKtr5%2BsNrC3cn%2BK6fA%2BOKsHEu7fixLqsO3dUnuA@mail.gmail.com> <CAPJ9Q0W4MggQ-BumAkNRXpR618JZPESyUWbLw8porD-J0ayeXQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Oct 21, 2011 at 14:56, Rohit J <mipsjunkie@gmail.com> wrote:
> the big picture story is that
> as a partial fix to using octeon specific very large mult instructions
> in our freebsd kernel
> (for crypto related ops), we had initially disabled
> interrupts=>context switches

Assuming you're using the stuff in-tree, that's my fault :)

> Need to see if there is a better way to do it.
> am now trying to see if it makes sense to save those registers and
> remove the disable interrupt constraint for running these large multiplication
> instructions.
> will be adapting the (multiplication context save/restore)
> in the octeon HRM and will revert if i have any further questions.

gonzo@ has incomplete patches, you may want to ask him.  Alternately,
look at how FPU context is lazily switched on other architectures.

In short (but not very short), you disable coprocessor 2 access and
enable it only on trap for userland processes.  And if there was
already a thread using cop2, then you save the state to its PCB and
reinitialize cop2 (this is important so you don't leak cryptographic
state to the next thread.)  And in the kernel when you use cop2, if
your thread was already using cop2 then you store cop2 state to the
stack as part of the save/restore blocks around the routines that
currently just use critical sections.  Then you do your work, and
context switches that happen are handled as normal (the kernel state
will be saved to the PCB.)  And then when you switch back, your kernel
routines keep operating.  And then on return you restore the state if
there was any, and clear it out otherwise, from the stack.

Depending on your application, you may want to use some other
synchronization mechanisms (like mutexes) to limit concurrent kernel
access to cop2, so you don't end up switching cop2 state back and
forth constantly for two threads that are trying to run, when it would
be much faster for one thread to simply block.

Hope that helps.  And do ask Oleskandr for his patches, if he still has them.

Note that whatever you end up with, do look at ways to add a little
bit of (compile-time) abstraction so that we can handle other variant
coprocessors on other ISAs.  Shouldn't be too hard, and the next
person can always make the modularization better, but it should help
structure and guide the implementation a little to keep that in mind.

Thanks,
Juli.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACVs6=9mKLreStSFgxqJ3eybPPX2ikMTx=7djjth6Bo_P52R4w>