From: Mike Kravetz <hidden> Date: 2006-08-02 17:59:33
In my last submission of hcall instrumentation patches, I took
Paul's suggestion and added code to get the timebase and PURR
snapshots in the hcall asm routines. I'm not confident in my
assembly skills, so I would really like some comments on this
approach/code. The idea(and some code) was taken from hash_low_64.S.
Of course, this all 'appears' to work correctly. :)
This patch is built on top of Anton's hcall cleanup patch. One
remaining issue is 'where should the statistic data structures
be updated?'. For simplicity, I have the asm code call the
following C routine to perform the updates.
void update_hcall_stats(unsigned long opcode, unsigned long tb_delta,
unsigned long purr_delta)
{
unsigned long op_index = opcode >> 2;
struct hcall_stats *hs = &__get_cpu_var(hcall_stats[op_index]);
hs->tb_total += tb_delta;
hs->purr_total += purr_delta;
hs->num_calls++;
}
I honestly do not know if it would be better to do all of this in the
assembly routine. I believe that 'allocation' of a stack frame is
only necessary because of the callout. Right?
--
Mike
diff -Naupr powerpc/arch/powerpc/platforms/pseries/hvCall.S powerpc.work/arch/powerpc/platforms/pseries/hvCall.S
At first I was concerned about macro expansion and knew a 'nop'
would be ok. Intended to go back and try 'blank', but forgot.
I'll give it a try.
--
Mike
At first I was concerned about macro expansion and knew a 'nop'
would be ok. Intended to go back and try 'blank', but forgot.
I'll give it a try.
What is the preferred method to 'leave it blank'?
#define HCALL_INST_PRECALL /* nop */
#define HCALL_INST_PRECALL ;
something else?
Leaving HCALL_INST_PRECALL undefined results in an assembler error.
--
Mike
From: Paul Mackerras <hidden> Date: 2006-08-07 06:26:24
Mike Kravetz writes:
This patch is built on top of Anton's hcall cleanup patch. One
remaining issue is 'where should the statistic data structures
be updated?'. For simplicity, I have the asm code call the
following C routine to perform the updates.
Hmmm, doing the update in assembly would avoid the need to create a
stack frame, which would be nice... Maybe we need to add some macros
to include/asm-powerpc/percpu.h to make it easier to access per-cpu
variables from assembly code.
Alternatively, we could put a pointer to the hcall_stats array for
each cpu in its paca. That's very easily accessed from assembly code.
Paul.
From: Mike Kravetz <hidden> Date: 2006-08-11 18:29:39
On Mon, Aug 07, 2006 at 04:26:24PM +1000, Paul Mackerras wrote:
Hmmm, doing the update in assembly would avoid the need to create a
stack frame, which would be nice... Maybe we need to add some macros
to include/asm-powerpc/percpu.h to make it easier to access per-cpu
variables from assembly code.
Alternatively, we could put a pointer to the hcall_stats array for
each cpu in its paca. That's very easily accessed from assembly code.
I finally got around to doing the update in assembly. I have attached
the code in question below. Macros were added (elsewhere) for things like
stat structure and offsets within the structure. No macros for per-cpu
data. Rather, I just used some existing definitions and based code on
descriptions in asm-powerpc/percpu.h. Let me know if this introduces too
many (unchecked at compile time assumptions) into the code.
The many comments are mostly for my benefit. :)
Thanks,
--
Mike
#define STK_PARM(i) (48 + ((i)-3)*8)
#ifdef CONFIG_HCALL_STATS
/*
* precall must preserve all registers. use unused STK_PARM()
* areas to save snapshots and opcode.
*/
#define HCALL_INST_PRECALL \
std r3,STK_PARM(r3)(r1); /* save opcode */ \
mftb r3; /* get timebase and */ \
std r3,STK_PARM(r5)(r1); /* save for later */ \
BEGIN_FTR_SECTION; \
mfspr r3,SPRN_PURR; /* get PURR and */ \
END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
std r3,STK_PARM(r6)(r1); /* save for later */ \
ld r3,STK_PARM(r3)(r1); /* opcode back in r3 */
/*
* postcall is performed immediately before function return which
* allows liberal use of non-volital registers.
*/
#define HCALL_INST_POSTCALL \
/* get time and PURR snapshots after hcall */ \
mftb r7; /* timebase after */ \
BEGIN_FTR_SECTION; \
mfspr r8,SPRN_PURR; /* PURR after */ \
END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
\
/* calculate time and PURR deltas for call */ \
ld r5,STK_PARM(r5)(r1); /* timebase before */ \
subf r5,r5,r7; \
ld r6,STK_PARM(r6)(r1); /* PURR before */ \
subf r6,r6,r8; \
\
/* calculate address of stat structure */ \
ld r4,STK_PARM(r3)(r1); /* use opcode as */ \
rldicl r4,r4,62,2; /* index into array */ \
mulli r4,r4,HCALL_STAT_SIZE; \
LOAD_REG_ADDR(r7, per_cpu__hcall_stats); \
add r4,r4,r7; \
ld r7,PACA_DATA_OFFSET(r13); /* per cpu offset */ \
add r4,r4,r7; \
\
/* update stats */ \
ld r7,HCALL_STAT_CALLS(r4); /* count */ \
addi r7,r7,1; \
std r7,HCALL_STAT_CALLS(r4); \
ld r7,HCALL_STAT_TB(r4); /* timebase */ \
add r7,r7,r5; \
std r7,HCALL_STAT_TB(r4); \
ld r7,HCALL_STAT_PURR(r4); /* PURR */ \
add r7,r7,r6; \
std r7,HCALL_STAT_PURR(r4);
#else
#define HCALL_INST_PRECALL
#define HCALL_INST_POSTCALL
#endif