problems solved
So, my CPU usage problems with tasks were due to my heavy use of mutex recursion. I got it for free in the kernel, so it made sense to do the same in userspace. But, syscall overhead was a big problem so I wrapped them with a simple class that seems to have solved the issue.
The reason I have a lot of mutex recursion is that there are many layers of functions that talk to certain pieces of hardware, and you may call them at the top or at the bottom. So, the mutex must be protected at every step.
This change reduced a 2ms periodic task from 25% cpu usage down to about 16.7%. A 22% usage 500 us periodic task was reduced to 15%. These two tasks work together to move and control a stepper motor and read all of its sensors and inputs. The same functionality in the old system with RTAI used about 25% of the CPU as measured by RTAI's stats stuff. (Perhaps this wasn't very accurate.) So I'm very pleased with the results, and feel there can probably be further optimization. (Obviously we expect some overhead in userspace.) This usage is down from over 50% CPU usage between the two tasks.
Steven