/*static char *SCCSID = "@(#) perfki.c 1.0 96/01/11";*/
#define SCCSID "@(#) perfki.c 1.0 96/01/11"

#define INCL_TYPES
#define INCL_ERRORS

#include <stdarg.h>
#include <basemac.h>
#include <basedef.h>
#include <bseerr.h>
#include <os2defp.h>
#include <bsememf.h>
#include <bsedosp.h>
#define FNO_NUM FNO_PERFSTEM_C
#include <fnotask.h>
#include <osmac.h>
#include <osconst.h>
#include <ostypes.h>
#include <proc.h>
#include <seldesc.h>
#include <mi.h>
#include <vmowner.h>
#include <infoseg.h>
#include <dossymc.h>
#include <curdir.h>
#include <dirent.h>
#include <find.h>
#include <screen.h>
#include <sigdef.h>
#include <except.h>
#include <sem.h>
#include <ioexp.h>
#include <pgexport.h>
#include <vmexport.h>
#include <selxport.h>
#include <tkexport.h>
#include <tkptda.h>
#include <ldrxport.h>
#include <kmode.h>
#include <..\memory\pglocal.h>

#ifdef SMP
#include <mplock.h>
#include <tkmp.h>
#else
extern ULONG KI_latch_lts;
#endif

extern void KIEnable();
extern void KIDisable();
extern void KILatch();

ULONG ki_enabled = 0;


/********* DosPerfSysCall routines (i.e., API defining) *********/

/*
 * PerfKIEnable
 */
int cdecl PerfKIEnable()
{
    KIEnable();
    return NO_ERROR;
}


/*
 * PerfKIDisable
 */
int cdecl PerfKIDisable()
{
    KIDisable();
    return NO_ERROR;
}


/*
 * PerfKIRdCnt
 */
int cdecl PerfKIRdCnt(char*  cntbuf)
{
    int  rc = NO_ERROR;
#ifdef SMP
    int  i;
    PSAVARS *pPSA;
#endif

    if (cntbuf) {
#ifdef SMP
        char *bp = cntbuf;
	KILatch();
        for (i = 0; i < cProcessors; i++) {
	    pPSA = MPGetPSAAddr(i);
            rc = TKSuBuff (bp, (char*) &pPSA->KI_latch_lts, 32,
			   (int) TK_UM_FATAL);
	    if (rc != NO_ERROR) return rc;
	    
	    bp += 32;
	}
#else
	KILatch();
	rc = TKSuBuff (cntbuf, (char*) &KI_latch_lts, 32, (int) TK_UM_FATAL);
#endif
    } else {
        rc = ERROR_INVALID_PARAMETER;
    }

    return rc;
}
