星期三, 11月 08, 2023

2008-06-20 如何判斷 AS/400 主機有幾顆 CPU ? (DSPCPUCNT with MI _MATMATR1)


如何判斷 AS/400 主機有幾顆 CPU ? (DSPCPUCNT with MI _MATMATR1)

File  : QRPGLESRC
Member: DSPCPUCNT
Type  : RPGLE
Usage : CRTBNDRPG DSPCPUCNT
        CALL DSPCPUCNT
OS Version: V5R1


     H DEBUG  OPTION(*SRCSTMT:*NODEBUGIO) DFTACTGRP(*NO) ACTGRP(*CALLER)

     D GetCPUCount     PR            10U 0 EXTPROC('GETCPUCOUNT')

     **-- Send program message:
     D SndPgmMsg       Pr                  ExtPgm( 'QMHSNDPM' )
     D  SpMsgId                       7a   Const
     D  SpMsgFq                      20a   Const
     D  SpMsgDta                    128a   Const
     D  SpMsgDtaLen                  10i 0 Const
     D  SpMsgTyp                     10a   Const
     D  SpCalStkE                    10a   Const  Options( *VarSize )
     D  SpCalStkCtr                  10i 0 Const
     D  SpMsgKey                      4a
     D  SpError                   32767a          Options( *VarSize )
     **-- Send completion message:
     D SndCmpMsg       Pr            10i 0
     D  PxMsgDta                    512a   Const  Varying

     **-- API error data structure:
     D ERRC0100        Ds                  Qualified
     D  BytPrv                       10i 0 Inz( %Size( ERRC0100 ))
     D  BytAvl                       10i 0
     D  MsgId                         7a
     D                                1a
     D  MsgDta                      128a

     D CPU_Count       S              5U 0

     C                   eval      *InLr = *On

     C                   eval      CPU_Count = GetCPUCount()

     C                   callp     SndCmpMsg(
     C                                       %editC(CPU_Count : '4') +
     C                                       ' CPUs detected.'
     C                                      )
     C                   return

      *=====================================================================
      * Get CPU count with MI _MATMATR1 option X'01DC'
      *=====================================================================
     P GetCPUCount     B                   Export
     D GetCPUCount     PI            10U 0

     D matmatr         PR                  extProc('_MATMATR1')
     D  MMTR_T                      256A   options(*VARSIZE)
     D  nOption                       5I 0 Const

     D CPU_Count       DS                  Inz Qualified
     D  nSize                        10I 0 inz(%Size(CPU_COUNT))
     D  nBytesRtn                    10I 0
     D  count                         5U 0

     D processor_cnt   C                   Const(X'01DC')

     C                   callP     matmatr(cpu_count : processor_cnt)
     C                   return    cpu_count.count

     P GetCPUCount     E

     **-- Send completion message:  ------------------------------------------**
     P SndCmpMsg       B
     D                 Pi            10i 0
     D  PxMsgDta                    512a   Const  Varying
     **
     D MsgKey          s              4a

     C                   Callp     SndPgmMsg( 'CPF9897'
     C                                       : 'QCPFMSG   *LIBL'
     C                                       : PxMsgDta
     C                                       : %Len( PxMsgDta )
     C                                       : '*COMP'
     C                                       : '*PGMBDY'
     C                                       : 1
     C                                       : MsgKey
     C                                       : ERRC0100
     C                                      )

     C                   If        ERRC0100.BytAvl > *Zero
     C                   Return    -1
     C                   Else
     C                   Return    0
     C                   EndIf
     **
     P SndCmpMsg       E

                



沒有留言: