├── .gitignore ├── tests ├── bin_ecb.config_3_0_CPU_CLK_UNHALTED.REF_TSC ├── bin_ecb.config_6_0_CPU_CLK_UNHALTED.REF_TSC ├── bin_ecb.config_3_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1 ├── bin_ecb.config_6_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1 ├── apps │ └── target │ │ ├── Makefile │ │ └── test.c ├── log.py ├── credentials.py ├── README ├── config.py └── operation.py ├── docs └── Analysis_Communication_Agent_Reference_Solution.pdf ├── CONTRIBUTING.md ├── LICENSE.txt ├── sepdk ├── src │ ├── inc │ │ ├── gmch.h │ │ ├── sepdrv_p_state.h │ │ ├── eventmux.h │ │ ├── silvermont.h │ │ ├── jkt_unc_ha.h │ │ ├── cpumon.h │ │ ├── core2.h │ │ ├── perfver4.h │ │ ├── pmi.h │ │ ├── sys_info.h │ │ ├── haswellunc_sa.h │ │ ├── jkt_unc_qpill.h │ │ ├── valleyview_sochap.h │ │ ├── linuxos.h │ │ ├── unc_gt.h │ │ ├── msrdefs.h │ │ ├── pmu_info_struct.h │ │ ├── apic.h │ │ ├── pmu_list.h │ │ ├── output.h │ │ ├── pmu_info_mmio.h │ │ ├── pmu_info.h │ │ ├── asm_helper.h │ │ ├── pci.h │ │ └── unc_common.h │ ├── sepdrv_p_state.c │ ├── sys64.S │ ├── apic.c │ ├── unc_sa.c │ ├── sys32.S │ └── Makefile └── include │ ├── lwpmudrv_gfx.h │ ├── lwpmudrv_version.h │ ├── lwpmudrv_types.h │ └── pax_shared.h ├── agentdk ├── Makefile ├── sepagent_parser.h ├── collection_traces.h ├── abstract_service.h ├── log.h ├── include │ ├── lwpmudrv_version.h │ └── lwpmudrv_types.h ├── communication.h ├── abstract.h └── sepagent_parser.c └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | sepagent 2 | *.la 3 | *.ko 4 | *.a 5 | *.so 6 | *.o 7 | *.cmd 8 | -------------------------------------------------------------------------------- /tests/bin_ecb.config_3_0_CPU_CLK_UNHALTED.REF_TSC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/aca/master/tests/bin_ecb.config_3_0_CPU_CLK_UNHALTED.REF_TSC -------------------------------------------------------------------------------- /tests/bin_ecb.config_6_0_CPU_CLK_UNHALTED.REF_TSC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/aca/master/tests/bin_ecb.config_6_0_CPU_CLK_UNHALTED.REF_TSC -------------------------------------------------------------------------------- /docs/Analysis_Communication_Agent_Reference_Solution.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/aca/master/docs/Analysis_Communication_Agent_Reference_Solution.pdf -------------------------------------------------------------------------------- /tests/bin_ecb.config_3_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/aca/master/tests/bin_ecb.config_3_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1 -------------------------------------------------------------------------------- /tests/bin_ecb.config_6_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/aca/master/tests/bin_ecb.config_6_0_UNC_IMC_DRAM_RW_SLICE0_UNC_IMC_DRAM_RW_SLICE1 -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution guidelines 2 | 3 | At this time, the Analysis Communication Agent github repository will be maintained by Intel Employees. Please contact us if you have suggestions, enhancements, or patches that you would like to contribute. 4 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /sepdk/src/inc/gmch.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _GMCH_H_ 35 | #define _GMCH_H_ 36 | 37 | extern CS_DISPATCH_NODE gmch_dispatch; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /tests/apps/target/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | CC = gcc 29 | CFLAGS = -Wall -pthread -O0 -xc++ -lstdc++ -shared-libgcc 30 | 31 | TARGET = test 32 | 33 | all: $(TARGET) 34 | 35 | $(TARGET): $(TARGET).c 36 | $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c 37 | 38 | clean: 39 | $(RM) $(TARGET) 40 | -------------------------------------------------------------------------------- /sepdk/src/inc/sepdrv_p_state.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2013-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _SEPDRV_P_STATE_H_ 34 | #define _SEPDRV_P_STATE_H_ 35 | 36 | #define DRV_APERF_MSR 0xE8 37 | #define DRV_MPERF_MSR 0xE7 38 | 39 | 40 | extern OS_STATUS 41 | SEPDRV_P_STATE_Read ( 42 | S8 *buffer, 43 | CPU_STATE pcpu 44 | ); 45 | 46 | #endif 47 | 48 | 49 | -------------------------------------------------------------------------------- /tests/log.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | 29 | import logging 30 | import os 31 | 32 | log = logging.getLogger('test_log') 33 | log.setLevel(logging.DEBUG) 34 | 35 | log_name = 'test_logs.txt' 36 | if os.path.exists(log_name): 37 | os.remove(log_name) 38 | 39 | ch = logging.FileHandler(log_name) 40 | formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s') 41 | 42 | ch.setLevel(logging.DEBUG) 43 | ch.setFormatter(formatter) 44 | 45 | log.addHandler(ch) 46 | -------------------------------------------------------------------------------- /sepdk/src/inc/eventmux.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | /* 34 | * cvs_id[] = "$Id$" 35 | */ 36 | 37 | #ifndef _EVENTMUX_H_ 38 | #define _EVENTMUX_H_ 39 | 40 | #include "lwpmudrv_ecb.h" 41 | #include "lwpmudrv_types.h" 42 | 43 | extern VOID 44 | EVENTMUX_Start ( 45 | VOID 46 | ); 47 | 48 | extern VOID 49 | EVENTMUX_Initialize ( 50 | VOID 51 | ); 52 | 53 | extern VOID 54 | EVENTMUX_Destroy ( 55 | VOID 56 | ); 57 | 58 | #endif /* _EVENTMUX_H_ */ 59 | 60 | -------------------------------------------------------------------------------- /agentdk/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | 29 | # -------------------- user configurable options ------------------------ 30 | 31 | SHELL = /bin/sh 32 | 33 | GCC = gcc 34 | CFLAGS = -g -O3 -I./include -DSTATIC_PROG_API 35 | OPTFLAGS = 36 | 37 | LDFLAGS = -lpthread -lstdc++ 38 | 39 | srcdir = . 40 | 41 | OBJS = abstract.o communication.o collection_traces.o sepagent.o sepagent_parser.o 42 | 43 | all: sepagent 44 | 45 | sepagent: $(OBJS) 46 | $(GCC) -g $(OBJS) -o sepagent $(LDFLAGS) 47 | 48 | clean: 49 | @rm -rf $(OBJS) $(GCC_EXE) *.o sepagent 50 | 51 | 52 | -------------------------------------------------------------------------------- /sepdk/src/inc/silvermont.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2011-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _SILVERMONT_H_ 34 | #define _SILVERMONT_H_ 35 | 36 | #include "msrdefs.h" 37 | extern DISPATCH_NODE silvermont_dispatch; 38 | extern DISPATCH_NODE knights_dispatch; 39 | 40 | #if defined(DRV_IA32) 41 | #define SILVERMONT_LBR_DATA_BITS 32 42 | #else 43 | #define SILVERMONT_LBR_DATA_BITS 48 44 | #endif 45 | 46 | #define SILVERMONT_LBR_BITMASK ((1ULL << SILVERMONT_LBR_DATA_BITS) -1) 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /sepdk/src/inc/jkt_unc_ha.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2012-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _JKTUNC_HA_H_INC_ 35 | #define _JKTUNC_HA_H_INC_ 36 | 37 | #define JKTUNC_HA_DID 0x3C46 38 | #define JKTUNC_HA_DEVICE_NO 14 39 | #define JKTUNC_HA_FUNC_NO 1 40 | #define JKTUNC_HA_D2C_OFFSET 0x84 41 | #define JKTUNC_HA_D2C_BITMASK 0x00000002 42 | #define JKTUNC_HA_D2C_DID 0x3CA0 43 | #define JKTUNC_HA_D2C_FUNC_NO 0 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /tests/credentials.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | 29 | import getpass 30 | 31 | 32 | class Credentials(object): 33 | def __init__(self, user=None, password=None): 34 | self.user = user 35 | self.password = password 36 | 37 | def _get_password(self): 38 | if self.password is None: 39 | self._get_user() 40 | self.password = getpass.getpass('Enter {} password: '.format(self.user)) 41 | 42 | def _get_user(self): 43 | if self.user is None: 44 | self.user = raw_input('Enter user name: ') 45 | 46 | def _get_credentials(self): 47 | self._get_user() 48 | self._get_password() 49 | -------------------------------------------------------------------------------- /sepdk/src/inc/cpumon.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _CPUMON_H_ 34 | #define _CPUMON_H_ 35 | 36 | #include 37 | #include "lwpmudrv_defines.h" 38 | 39 | /* 40 | * Defines 41 | */ 42 | 43 | 44 | /** 45 | * Function Declarations 46 | */ 47 | 48 | /* 49 | * CPUMON control functions 50 | */ 51 | 52 | extern VOID CPUMON_Install_Cpuhooks(VOID); 53 | extern VOID CPUMON_Remove_Cpuhooks(VOID); 54 | #if defined(DRV_CPU_HOTPLUG) 55 | extern DRV_BOOL CPUMON_is_Online_Allowed(VOID); 56 | extern DRV_BOOL CPUMON_is_Offline_Allowed(VOID); 57 | extern VOID CPUMON_Online_Cpu(PVOID parm); 58 | extern VOID CPUMON_Offline_Cpu(PVOID parm); 59 | #endif 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /sepdk/include/lwpmudrv_gfx.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _LWPMUDRV_GFX_H_ 30 | #define _LWPMUDRV_GFX_H_ 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | #define GFX_BASE_ADDRESS 0xFF200000 37 | #define GFX_BASE_NEW_OFFSET 0x00080000 38 | #define GFX_PERF_REG 0x040 // location of GFX counter relative to base 39 | #define GFX_NUM_COUNTERS 9 // max number of GFX counters per counter group 40 | #define GFX_CTR_OVF_VAL 0xFFFFFFFF // overflow value for GFX counters 41 | 42 | #define GFX_REG_CTR_CTRL 0x01FF 43 | #define GFX_CTRL_DISABLE 0x1E00 44 | 45 | //#define GFX_COMPUTE_DELTAS 1 // use event count deltas instead of raw counts 46 | 47 | #if defined(__cplusplus) 48 | } 49 | #endif 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /sepdk/src/inc/core2.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _CORE2_H_ 34 | #define _CORE2_H_ 35 | 36 | #include "msrdefs.h" 37 | 38 | extern DISPATCH_NODE core2_dispatch; 39 | extern DISPATCH_NODE corei7_dispatch; 40 | extern DISPATCH_NODE corei7_dispatch_nehalem; 41 | extern DISPATCH_NODE corei7_dispatch_htoff_mode; 42 | extern DISPATCH_NODE corei7_dispatch_2; 43 | extern DISPATCH_NODE corei7_dispatch_htoff_mode_2; 44 | 45 | #define CORE2UNC_BLBYPASS_BITMASK 0x00000001 46 | #define CORE2UNC_DISABLE_BL_BYPASS_MSR 0x39C 47 | 48 | #if defined(DRV_IA32) 49 | #define CORE2_LBR_DATA_BITS 32 50 | #else 51 | #define CORE2_LBR_DATA_BITS 48 52 | #endif 53 | 54 | #define CORE2_LBR_BITMASK ((1ULL << CORE2_LBR_DATA_BITS) -1) 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /sepdk/src/inc/perfver4.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2013-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _PERFVER4_H_ 34 | #define _PERFVER4_H_ 35 | 36 | #include "msrdefs.h" 37 | 38 | extern DISPATCH_NODE perfver4_dispatch; 39 | extern DISPATCH_NODE perfver4_dispatch_htoff_mode; 40 | extern DISPATCH_NODE perfver4_dispatch_nonht_mode; 41 | 42 | #define PERFVER4_UNC_BLBYPASS_BITMASK 0x00000001 43 | #define PERFVER4_UNC_DISABLE_BL_BYPASS_MSR 0x39C 44 | 45 | #if defined(DRV_IA32) 46 | #define PERFVER4_LBR_DATA_BITS 32 47 | #else 48 | #define PERFVER4_LBR_DATA_BITS 57 49 | #endif 50 | 51 | #define PERFVER4_LBR_BITMASK ((1ULL << PERFVER4_LBR_DATA_BITS) -1) 52 | 53 | #define PERFVER4_FROZEN_BIT_MASK 0xc00000000000000ULL 54 | #define PERFVER4_OVERFLOW_BIT_MASK_HT_ON 0x600000070000000FULL 55 | #define PERFVER4_OVERFLOW_BIT_MASK_HT_OFF 0x60000007000000FFULL 56 | #define PERFVER4_OVERFLOW_BIT_MASK_NON_HT 0x6000000F000000FFULL 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /sepdk/src/inc/pmi.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _PMI_H_ 35 | #define _PMI_H_ 36 | 37 | #include "lwpmudrv_defines.h" 38 | #include 39 | #include 40 | 41 | #if defined(DRV_IA32) 42 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 43 | #define REGS_xcs(regs) regs->xcs 44 | #define REGS_eip(regs) regs->eip 45 | #define REGS_eflags(regs) regs->eflags 46 | #else 47 | #define REGS_xcs(regs) regs->cs 48 | #define REGS_eip(regs) regs->ip 49 | #define REGS_eflags(regs) regs->flags 50 | #endif 51 | #endif 52 | 53 | #if defined(DRV_EM64T) 54 | #define REGS_cs(regs) regs->cs 55 | 56 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 57 | #define REGS_rip(regs) regs->rip 58 | #define REGS_eflags(regs) regs->eflags 59 | #else 60 | #define REGS_rip(regs) regs->ip 61 | #define REGS_eflags(regs) regs->flags 62 | #endif 63 | #endif 64 | 65 | asmlinkage VOID PMI_Interrupt_Handler(struct pt_regs *regs); 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /agentdk/sepagent_parser.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _SEPAGENT_PARSER_H_ 30 | #define _SEPAGENT_PARSER_H_ 31 | /* 32 | * File: sepagent_parser.h 33 | */ 34 | 35 | /* ------------------------------------------------------------------------- */ 36 | /*! 37 | * @fn void sepagent_Print_help (void) 38 | * 39 | * @brief Print the usage messsage 40 | * 41 | * @param NONE 42 | * 43 | * @return NONE 44 | * 45 | * Special Notes: 46 | * Prints out detailed usage message. 47 | */ 48 | extern void 49 | SEPAGENT_Print_Help( 50 | void 51 | ); 52 | 53 | 54 | /* ------------------------------------------------------------------------- */ 55 | /*! 56 | * @fn int sepagent_Parser 57 | * 58 | * @brief Parse the command line arguments 59 | * 60 | * @param IN num_args - Number of arguments 61 | * @param IN my_argv[] - the args list 62 | * @param OUT *data_transfer_mode - data transfer mode 63 | * 64 | * @return NONE 65 | * 66 | * Special Notes: None 67 | */ 68 | // Partial implemetation 69 | extern int 70 | SEPAGENT_Parser( 71 | int num_args, 72 | char *options_arr[], 73 | int *data_transfer_mode 74 | ); 75 | 76 | #endif // _SEPAGENT_PARSER_H_ 77 | 78 | -------------------------------------------------------------------------------- /sepdk/src/inc/sys_info.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _SYS_INFO_H_ 35 | #define _SYS_INFO_H_ 36 | 37 | #include "lwpmudrv_defines.h" 38 | 39 | #define KNIGHTS_FAMILY 0x06 40 | #define KNL_MODEL 0x57 41 | #define KNM_MODEL 0x85 42 | 43 | #define is_Knights_family(family, model) ((family==KNIGHTS_FAMILY)&&((model==KNL_MODEL)||(model==KNM_MODEL))) 44 | 45 | typedef struct __generic_ioctl { 46 | U32 size; 47 | S32 ret; 48 | U64 rsv[3]; 49 | } GENERIC_IOCTL; 50 | 51 | #define GENERIC_IOCTL_size(gio) (gio)->size 52 | #define GENERIC_IOCTL_ret(gio) (gio)->ret 53 | 54 | // 55 | // This one is unusual in that it's really a variable 56 | // size. The system_info field is just a easy way 57 | // to access the base information, but the actual size 58 | // when used tends to be much larger that what is 59 | // shown here. 60 | // 61 | typedef struct __system_info { 62 | GENERIC_IOCTL gen; 63 | VTSA_SYS_INFO sys_info; 64 | } IOCTL_SYS_INFO; 65 | 66 | #define IOCTL_SYS_INFO_gen(isi) (isi)->gen 67 | #define IOCTL_SYS_INFO_sys_info(isi) (isi)->sys_info 68 | 69 | extern U32 SYS_INFO_Build (void); 70 | extern void SYS_INFO_Transfer (PVOID buf_usr_to_drv, unsigned long len_usr_to_drv); 71 | extern void SYS_INFO_Destroy (void); 72 | extern void SYS_INFO_Build_Cpu (PVOID param); 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /tests/README: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | 29 | Validated on python 2.7 30 | 31 | Usage: 32 | Target platform preparation. 33 | Build test target application 34 | > cd ./apps/target 35 | > make 36 | > cd - 37 | 38 | Copy target application to the target 39 | > scp ./apps/target/test user@target 40 | 41 | Start application on target with number of cores specified (8 in the example) 42 | > ssh user@target "./test -nt 8" 43 | 44 | The application will give output like this: 45 | > nt = 8 46 | > dataSize = 0x10000 47 | > Hotspot ip: 400AD1 : 4197073 48 | > numberOfThreads = 8 49 | 50 | Configuration: 51 | The configuration file is located in ./config.py 52 | You need to change it according you target machine. For example 53 | 54 | def ApolloLakePremiumSKU(self): 55 | self.cores_number = 8 # Number of cores the platform have 56 | self.testapp = 'test' # Name of test application. On some platforms may be used full path of application 57 | self.testapp_hotspot_ip = 0x400AD1 # The ip take from target application 58 | self.protocol_version = 6 # Internal protocol version 59 | 60 | Testing: 61 | Form directory with test run: 62 | > python test.py 127.0.0.1 ApolloLakePremiumSKU 63 | 64 | Where the configuration type is the same as in config.py 65 | -------------------------------------------------------------------------------- /tests/config.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | 29 | import argparse 30 | 31 | 32 | class Config(object): 33 | def __init__(self): 34 | parser = argparse.ArgumentParser(description="Tests for remote SEP target.") 35 | parser.add_argument(dest='target_ip', help='IP address for the remote target') 36 | parser.add_argument(dest='config_type', help='target type defined in config.py') 37 | parser.add_argument('-p', '--port', dest='target_port', default=9321, 38 | help='remote target port', type=int) 39 | args = parser.parse_args() 40 | 41 | self.target_ip = args.target_ip 42 | self.target_port = args.target_port 43 | self.cores_number = None 44 | self.uncore_supported = False 45 | 46 | try: 47 | getattr(self, args.config_type)() 48 | except AttributeError: 49 | raise Exception("Incorrect config type specified.") 50 | 51 | def ApolloLakePremiumSKU(self): 52 | self.cores_number = 4 53 | self.testapp = '/usr/user/test' 54 | self.testapp_hotspot_ip = 0x804900F 55 | self.uncore_supported = False 56 | self.protocol_version = 6 57 | 58 | def Xeon(self): 59 | self.cores_number = 88 60 | self.testapp = '/home/vtune/workspace/sampling/ref_tests/apps/one_test/test' 61 | self.testapp_hotspot_ip = 0x400B0D 62 | self.uncore_supported = False 63 | self.protocol_version = 6 64 | 65 | -------------------------------------------------------------------------------- /sepdk/src/inc/haswellunc_sa.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2011-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _HSWUNC_SA_H_INC_ 34 | #define _HSWUNC_SA_H_INC_ 35 | 36 | /* 37 | * Local to this architecture: Haswell uncore SA unit 38 | * 39 | */ 40 | #define HSWUNC_SA_DESKTOP_DID 0x000C04 41 | #define HSWUNC_SA_NEXT_ADDR_OFFSET 4 42 | #define HSWUNC_SA_BAR_ADDR_SHIFT 32 43 | #define HSWUNC_SA_BAR_ADDR_MASK 0x0007FFFFFF000LL 44 | #define HSWUNC_SA_MAX_PCI_DEVICES 16 45 | #define HSWUNC_SA_MAX_COUNT 0x00000000FFFFFFFFLL 46 | #define HSWUNC_SA_MAX_COUNTERS 8 47 | 48 | #define HSWUNC_SA_MCHBAR_MMIO_PAGE_SIZE 8*4096 49 | #define HSWUNC_SA_PCIEXBAR_MMIO_PAGE_SIZE 57*4096 50 | #define HSWUNC_SA_OTHER_BAR_MMIO_PAGE_SIZE 4096 51 | #define HSWUNC_SA_GDXCBAR_OFFSET_LO 0x5420 52 | #define HSWUNC_SA_GDXCBAR_OFFSET_HI 0x5424 53 | #define HSWUNC_SA_GDXCBAR_MASK 0x7FFFFFF000LL 54 | #define HSWUNC_SA_CHAP_SAMPLE_DATA 0x00020000 55 | #define HSWUNC_SA_CHAP_STOP 0x00040000 56 | #define HSWUNC_SA_CHAP_CTRL_REG_OFFSET 0x0 57 | 58 | #define HSWUNC_SA_PAGE_MASK 0xfffffffffffff000 59 | #define HSWUNC_SA_PAGE_OFFSET_MASK 0xfff 60 | #define HSWUNC_SA_PAGE_SIZE 0x1000 61 | 62 | 63 | extern DISPATCH_NODE hswunc_sa_dispatch; 64 | 65 | #endif 66 | 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | 11 | Contact: webadmin@linux.intel.com 12 | # Analysis Communication Agent Reference Solution 13 | 14 | ## Introduction 15 | Analysis Communication Agent enables performance analysis of custom embedded operating systems (OS) or real-time operating systems (RTOS) and the applications running on them using Intel® VTuneTM Profiler. This reference implementation provides guidance on enabling a sampling collector for this purpose. 16 | 17 | ## What is Intel® VTune Profiler? 18 | Intel® VTuneTM Profiler is a performance analysis tool that can be used to profile and optimize application performance. For more information, please check [here](https://software.intel.com/en-us/vtune). 19 | 20 | ## License 21 | The Analysis Communication Agent reference solution is distributed under the MIT License. 22 | 23 | You may obtain a copy of the License at: https://opensource.org/licenses/MIT 24 | 25 | ## Supported OS Platforms 26 | This reference solutuon is implemented for Linux operating system. However, you can implement the Analysis Communication Agent and the sampling driver for any embedded operating system compatible with Intel® VTuneTM Profiler for data collection and visualization. 27 | 28 | ## Supported Hardware Platforms 29 | The reference solution works on any of the recent Intel hardware platforms. 30 | 31 | ## Documentation 32 | Please refer to the [docs](https://github.com/intel/aca/blob/master/docs) folder for detailed documentation of the Analysis Communication Agent reference solution architecture, implementation, and how to run the collections. 33 | 34 | ## How to provide feedback 35 | By default, please submit an issue using native github.com [interface](https://github.com/intel/aca/issues). 36 | 37 | ## How to contribute 38 | Please check the [contribution guidelines](https://github.com/intel/aca/blob/master/CONTRIBUTING.md) 39 | 40 | ## See also 41 | * [Contribution guidelines](https://github.com/intel/compute-runtime/blob/master/CONTRIBUTING.md) 42 | * [License](https://github.com/intel/aca/blob/master/LICENSE.txt) 43 | * [Documentation](https://github.com/intel/aca/blob/master/docs) 44 | * [Intel VTune Profiler](https://software.intel.com/en-us/vtune) 45 | -------------------------------------------------------------------------------- /sepdk/src/inc/jkt_unc_qpill.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _JKTUNC_QPILL_H_INC_ 35 | #define _JKTUNC_QPILL_H_INC_ 36 | 37 | /* 38 | * Local to this architecture: JKT uncore QPILL unit 39 | * 40 | */ 41 | #define JKTUNC_QPILL0_DID 0x3C41 // --- QPILL0 PerfMon DID --- B:D 1:8:2 42 | #define JKTUNC_QPILL_MM0_DID 0x3C86 // --- QPILL0 PerfMon MM Config DID --- B:D 1:8:6 43 | #define JKTUNC_QPILL1_DID 0x3C42 // --- QPILL1 PerfMon DID --- B:D 1:9:2 44 | #define JKTUNC_QPILL2_DID 0x3C44 // --- QPILL0 PerfMon DID --- B:D 1:8:2 45 | #define JKTUNC_QPILL3_DID 0x3C45 // --- QPILL0 PerfMon DID --- B:D 1:8:2 46 | #define JKTUNC_QPILL_MM1_DID 0x3C96 // --- QPILL1 PerfMon MM Config DID --- B:D 1:9:6 47 | #define JKTUNC_QPILL_MCFG_DID 0x3C28 // --- QPILL1 PerfMon MCFG DID --- B:D 0:5:0 48 | #define JKTUNC_QPILL0_D2C_DID 0x3C80 // --- D2C QPILL Port 1 config DID B:D:F X:8:0 49 | #define JKTUNC_QPILL1_D2C_DID 0x3C90 // --- D2C QPILL Port 2 config DID B:D:F X:9:0 50 | 51 | #define JKTUNC_QPILL_PERF_GLOBAL_CTRL 0x391 52 | 53 | #define IA32_DEBUG_CTRL 0x1D9 54 | 55 | #define JKTUNC_QPILL_D2C_OFFSET 0x80 56 | #define JKTUNC_QPILL_D2C_BITMASK 0x00000002 57 | #define JKTUNC_QPILL_FUNC_NO 2 58 | #define JKTUNC_QPILL_D2C_FUNC_NO 0 59 | 60 | extern DISPATCH_NODE jktunc_qpill_dispatch; 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /sepdk/src/inc/valleyview_sochap.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2012-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _VALLEYVIEW_SOCHAP_H_INC_ 34 | #define _VALLEYVIEW_SOCHAP_H_INC_ 35 | 36 | /* 37 | * Local to this architecture: Valleyview uncore SA unit 38 | * 39 | */ 40 | #define VLV_VISA_DESKTOP_DID 0x000C04 41 | #define VLV_VISA_NEXT_ADDR_OFFSET 4 42 | #define VLV_VISA_BAR_ADDR_SHIFT 32 43 | #define VLV_VISA_BAR_ADDR_MASK 0x000FFFC00000LL 44 | #define VLV_VISA_MAX_PCI_DEVICES 16 45 | #define VLV_VISA_MCR_REG_OFFSET 0xD0 46 | #define VLV_VISA_MDR_REG_OFFSET 0xD4 47 | #define VLV_VISA_MCRX_REG_OFFSET 0xD8 48 | #define VLV_VISA_BYTE_ENABLES 0xF 49 | #define VLV_VISA_OP_CODE_SHIFT 24 50 | #define VLV_VISA_PORT_ID_SHIFT 16 51 | #define VLV_VISA_OFFSET_HI_MASK 0xFF 52 | #define VLV_VISA_OFFSET_LO_MASK 0xFF 53 | #define VLV_CHAP_SIDEBAND_PORT_ID 23 54 | #define VLV_CHAP_SIDEBAND_WRITE_OP_CODE 1 55 | #define VLV_CHAP_SIDEBAND_READ_OP_CODE 0 56 | #define VLV_CHAP_MAX_COUNTERS 8 57 | #define VLV_CHAP_MAX_COUNT 0x00000000FFFFFFFFLL 58 | 59 | #define VLV_VISA_OTHER_BAR_MMIO_PAGE_SIZE 4096 60 | #define VLV_VISA_CHAP_SAMPLE_DATA 0x00020000 61 | #define VLV_VISA_CHAP_STOP 0x00040000 62 | #define VLV_VISA_CHAP_START 0x00110000 63 | #define VLV_VISA_CHAP_CTRL_REG_OFFSET 0x0 64 | 65 | 66 | extern DISPATCH_NODE valleyview_visa_dispatch; 67 | 68 | #endif 69 | 70 | -------------------------------------------------------------------------------- /agentdk/collection_traces.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _COLLECTION_TRACES_H_ 30 | #define _COLLECTION_TRACES_H_ 31 | 32 | // Auto collection mode allows to collect samples 33 | // in a prespecified configuration 34 | // without any communication from host. 35 | // The sampled data will be buffered on target memory 36 | // until host connection is made to fetch them over network. 37 | 38 | // Set the default mode to TRUE to enable the auto collection mode 39 | // 0 : No auto collection 40 | // 1 : Fixed counters collection only 41 | // 2 : Fixed counters and LBR data collection 42 | #define DEFAULT_AUTO_COLLECTION_MODE 2 43 | 44 | // Set the collection time in second 45 | #define ADV_HOTSPOT_COLLECTION_DURATION_SEC 10 46 | 47 | // Set the per-cpu sample buffer size in memory 48 | // Samples captured after buffer gets full will be discarded. 49 | #define AUTO_COLLECTION_SAMP_BUFFER_SIZE (1<<22) // 4MB per cpu 50 | 51 | #define AUTO_COLLECTION_MOD_BUFFER_CHUNK_SIZE 4096 // Increase by 4KB 52 | 53 | #define ADV_HOTSPOT_COLLECTION_TRACE_LENGTH 21 54 | #define ADV_HOTSPOT_LBR_COLLECTION_TRACE_LENGTH 22 55 | 56 | #define CMD_TRACE_SIZE 24 57 | #define ARG_TRACE_SIZE 4300 58 | 59 | extern S8 adv_hotspot_cmd_traces[ADV_HOTSPOT_COLLECTION_TRACE_LENGTH][CMD_TRACE_SIZE]; 60 | extern S8 adv_hotspot_arg_traces[ADV_HOTSPOT_COLLECTION_TRACE_LENGTH][ARG_TRACE_SIZE]; 61 | //extern S8 *adv_hotspot_ret_traces[ADV_HOTSPOT_COLLECTION_TRACE_LENGTH]; 62 | 63 | extern S8 adv_hotspot_lbr_cmd_traces[ADV_HOTSPOT_LBR_COLLECTION_TRACE_LENGTH][CMD_TRACE_SIZE]; 64 | extern S8 adv_hotspot_lbr_arg_traces[ADV_HOTSPOT_LBR_COLLECTION_TRACE_LENGTH][ARG_TRACE_SIZE]; 65 | //extern S8 *adv_hotspot_lbr_ret_traces[ADV_HOTSPOT_LBR_COLLECTION_TRACE_LENGTH]; 66 | 67 | extern U32 auto_collection_mode; 68 | extern U32 trace_length; 69 | extern S8 *cmd_traces; 70 | extern S8 *arg_traces; 71 | extern S8 **ret_traces; 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /sepdk/src/inc/linuxos.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _LINUXOS_H_ 34 | #define _LINUXOS_H_ 35 | 36 | // defines for options parameter of samp_load_image_notify_routine() 37 | #define LOPTS_1ST_MODREC 0x1 38 | #define LOPTS_GLOBAL_MODULE 0x2 39 | #define LOPTS_EXE 0x4 40 | 41 | #define FOR_EACH_TASK for_each_process 42 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,19,00) 43 | #define DRV_F_DENTRY f_path.dentry 44 | #else 45 | #define DRV_F_DENTRY f_dentry 46 | #endif 47 | 48 | #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) 49 | #define D_PATH(vm_file, name, maxlen) \ 50 | d_path((vm_file)->f_dentry, (vm_file)->f_vfsmnt, (name), (maxlen)) 51 | #else 52 | #define D_PATH(vm_file, name, maxlen) \ 53 | d_path(&((vm_file)->f_path), (name), (maxlen)) 54 | #endif 55 | 56 | #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) 57 | #define DRV_VM_MOD_EXECUTABLE(vma) \ 58 | (vma->vm_flags & VM_EXECUTABLE) 59 | #else 60 | #define DRV_VM_MOD_EXECUTABLE(vma) \ 61 | (linuxos_Equal_VM_Exe_File(vma)) 62 | #define DRV_MM_EXE_FILE_PRESENT 63 | #endif 64 | 65 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32) 66 | #define DRV_ALLOW_VDSO 67 | #endif 68 | 69 | #if defined(DRV_IA32) 70 | #define FIND_VMA(mm, data) find_vma ((mm), (U32)(data)); 71 | #endif 72 | #if defined(DRV_EM64T) 73 | #define FIND_VMA(mm, data) find_vma ((mm), (U64)(data)); 74 | #endif 75 | 76 | extern VOID 77 | LINUXOS_Install_Hooks ( 78 | VOID 79 | ); 80 | 81 | extern VOID 82 | LINUXOS_Uninstall_Hooks ( 83 | VOID 84 | ); 85 | 86 | extern OS_STATUS 87 | LINUXOS_Enum_Process_Modules ( 88 | DRV_BOOL at_end 89 | ); 90 | 91 | extern DRV_BOOL 92 | LINUXOS_Check_KVM_Guest_Process ( 93 | VOID 94 | ); 95 | #if defined(DRV_CPU_HOTPLUG) 96 | extern VOID 97 | LINUXOS_Register_Hotplug( 98 | VOID 99 | ); 100 | 101 | extern VOID 102 | LINUXOS_Unregister_Hotplug( 103 | VOID 104 | ); 105 | #endif 106 | #endif 107 | 108 | -------------------------------------------------------------------------------- /sepdk/src/inc/unc_gt.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _UNC_GT_H_INC_ 34 | #define _UNC_GT_H_INC_ 35 | 36 | /* 37 | * Local to this architecture: SNB uncore GT unit 38 | * 39 | */ 40 | #define GT_MMIO_SIZE 0x200000 41 | #define NEXT_ADDR_OFFSET 4 42 | #define UNC_GT_BAR_MASK 0x7FFF000000 43 | #define PERF_GLOBAL_CTRL 0x391 44 | #define GT_CLEAR_COUNTERS 0xFFFF0000 45 | 46 | #define GT_DID_1 0x102 47 | #define INTEL_VENDOR_ID 0x8086 48 | #define DRV_GET_PCI_VENDOR_ID(value) value & 0x0000FFFF 49 | #define DRV_GET_PCI_DEVICE_ID(value) (value & 0xFFFF0000) >> 16 50 | #define DRV_IS_INTEL_VENDOR_ID(value) value == INTEL_VENDOR_ID 51 | #define DRV_IS_GT_DEVICE_ID(value) value == GT_DID_1 52 | 53 | //clock gating disable values 54 | #define UNC_GT_GCPUNIT_REG1 0x9400 55 | #define UNC_GT_GCPUNIT_REG2 0x9404 56 | #define UNC_GT_GCPUNIT_REG3 0x9408 57 | #define UNC_GT_GCPUNIT_REG4 0x940c 58 | #define UNC_GT_GCPUNIT_REG1_VALUE 0xffffffff 59 | #define UNC_GT_GCPUNIT_REG2_VALUE 0xffffffff 60 | #define UNC_GT_GCPUNIT_REG3_VALUE 0xffe3ffff 61 | #define UNC_GT_GCPUNIT_REG4_VALUE 0x00000003 62 | //RC6 disable 63 | #define UNC_GT_RC6_REG1 0xa090 64 | #define UNC_GT_RC6_REG2 0xa094 65 | #define UNC_GT_RC6_REG1_OR_VALUE 0x80000000 66 | #define UNC_GT_RC6_REG2_VALUE 0x00000000 67 | extern DISPATCH_NODE unc_gt_dispatch; 68 | 69 | typedef struct GT_CTR_NODE_S GT_CTR_NODE; 70 | typedef GT_CTR_NODE *GT_CTR; 71 | struct GT_CTR_NODE_S 72 | { 73 | union 74 | { 75 | struct 76 | { 77 | U32 low: 32; 78 | U32 high : 12; 79 | } bits; 80 | U64 value; 81 | } u; 82 | }; 83 | 84 | #define GT_CTR_NODE_value(x) x.u.value 85 | #define GT_CTR_NODE_low(x) x.u.bits.low 86 | #define GT_CTR_NODE_high(x) x.u.bits.high 87 | #define GT_CTR_NODE_value_reset(x) x.u.value = 0 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /sepdk/src/inc/msrdefs.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2011-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _MSRDEFS_H_ 35 | #define _MSRDEFS_H_ 36 | 37 | /* 38 | * Arch Perf monitoring version 3 39 | */ 40 | #define IA32_PMC0 0x0C1 41 | #define IA32_PMC1 0x0C2 42 | #define IA32_PMC2 0x0C3 43 | #define IA32_PMC3 0x0C4 44 | #define IA32_PMC4 0x0C5 45 | #define IA32_PMC5 0x0C6 46 | #define IA32_PMC6 0x0C7 47 | #define IA32_PMC7 0x0C8 48 | #define IA32_FULL_PMC0 0x4C1 49 | #define IA32_FULL_PMC1 0x4C2 50 | #define IA32_PERFEVTSEL0 0x186 51 | #define IA32_PERFEVTSEL1 0x187 52 | #define IA32_FIXED_CTR0 0x309 53 | #define IA32_FIXED_CTR1 0x30A 54 | #define IA32_FIXED_CTR2 0x30B 55 | #define IA32_FIXED_CTR3 0x30C 56 | #define IA32_PERF_CAPABILITIES 0x345 57 | #define IA32_FIXED_CTRL 0x38D 58 | #define IA32_PERF_GLOBAL_STATUS 0x38E 59 | #define IA32_PERF_GLOBAL_CTRL 0x38F 60 | #define IA32_PERF_GLOBAL_OVF_CTRL 0x390 61 | #define IA32_PEBS_ENABLE 0x3F1 62 | #define IA32_MISC_ENABLE 0x1A0 63 | #define IA32_DS_AREA 0x600 64 | #define IA32_DEBUG_CTRL 0x1D9 65 | #undef IA32_LBR_FILTER_SELECT 66 | #define IA32_LBR_FILTER_SELECT 0x1c8 67 | #define IA32_PEBS_FRONTEND 0x3F7 68 | #define IA32_PERF_METRICS 0x329 69 | 70 | #define COMPOUND_CTR_CTL 0x306 71 | #define COMPOUND_PERF_CTR 0x307 72 | #define COMPOUND_CTR_OVF_BIT 0x800 73 | #define COMPOUND_CTR_OVF_SHIFT 12 74 | 75 | #define FIXED_CORE_CYCLE_GLOBAL_CTRL_MASK 0x200000000 76 | #define FIXED_CORE_CYCLE_FIXED_CTRL_MASK 0xF0 77 | 78 | // REG INDEX inside GLOBAL CTRL SECTION 79 | enum { 80 | GLOBAL_CTRL_REG_INDEX = 0, 81 | GLOBAL_OVF_CTRL_REG_INDEX, 82 | PEBS_ENABLE_REG_INDEX, 83 | DEBUG_CTRL_REG_INDEX, 84 | FIXED_CTRL_REG_INDEX, 85 | }; 86 | 87 | // REG INDEX inside GLOBAL STATUS SECTION 88 | enum { 89 | GLOBAL_STATUS_REG_INDEX = 0, 90 | }; 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /sepdk/src/sepdrv_p_state.c: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2013-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #include "lwpmudrv_defines.h" 34 | #include "lwpmudrv_types.h" 35 | #include "inc/control.h" 36 | #include "inc/utility.h" 37 | #include "inc/sepdrv_p_state.h" 38 | 39 | /*! 40 | * @fn OS_STATUS SEPDRV_P_STATE_Read 41 | * 42 | * @brief Reads the APERF and MPERF counters into the buffer provided for the purpose 43 | * 44 | * @param buffer - buffer to read the counts into 45 | * 46 | * @param pcpu - pcpu struct that contains the previous APERF/MPERF values 47 | * 48 | * @return OS_SUCCESS if read succeeded, otherwise error 49 | * 50 | * @note 51 | */ 52 | extern OS_STATUS 53 | SEPDRV_P_STATE_Read ( 54 | S8 *buffer, 55 | CPU_STATE pcpu 56 | ) 57 | { 58 | U64 *samp = (U64 *)buffer; 59 | U64 new_APERF = 0; 60 | U64 new_MPERF = 0; 61 | 62 | SEP_DRV_LOG_TRACE_IN("Buffer: %p, pcpu: %p.", buffer, pcpu); 63 | 64 | if ((samp == NULL) || (pcpu == NULL)) { 65 | SEP_DRV_LOG_ERROR_TRACE_OUT("OS_INVALID (!samp || !pcpu)."); 66 | return OS_INVALID; 67 | } 68 | 69 | new_APERF = SYS_Read_MSR(DRV_APERF_MSR); 70 | new_MPERF = SYS_Read_MSR(DRV_MPERF_MSR); 71 | 72 | if (CPU_STATE_last_p_state_valid(pcpu)) { 73 | // there is a previous APERF/MPERF value 74 | if ((CPU_STATE_last_aperf(pcpu)) > new_APERF) { 75 | // a wrap-around has occurred. 76 | samp[1] = CPU_STATE_last_aperf(pcpu) - new_APERF; 77 | } 78 | else { 79 | samp[1] = new_APERF - CPU_STATE_last_aperf(pcpu); 80 | } 81 | 82 | if ((CPU_STATE_last_mperf(pcpu)) > new_MPERF) { 83 | // a wrap-around has occurred. 84 | samp[0] = CPU_STATE_last_mperf(pcpu) - new_MPERF; 85 | } 86 | else { 87 | samp[0] = new_MPERF - CPU_STATE_last_mperf(pcpu); 88 | } 89 | } 90 | else { 91 | // there is no previous valid APERF/MPERF values, thus no delta calculations 92 | (CPU_STATE_last_p_state_valid(pcpu)) = TRUE; 93 | samp[0] = 0; 94 | samp[1] = 0; 95 | } 96 | 97 | CPU_STATE_last_aperf(pcpu) = new_APERF; 98 | CPU_STATE_last_mperf(pcpu) = new_MPERF; 99 | 100 | SEP_DRV_LOG_TRACE_OUT("OS_SUCCESS."); 101 | return OS_SUCCESS; 102 | } 103 | 104 | -------------------------------------------------------------------------------- /agentdk/abstract_service.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | /* 30 | * File : abstract.h 31 | */ 32 | 33 | #ifndef _ABSTRACT_SERVICE_H_INC_ 34 | #define _ABSTRACT_SERVICE_H_INC_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #define DRV_PAUSE_SIGNAL 0 41 | #define DRV_RESUME_SIGNAL 1 42 | #define DRV_STOP_SIGNAL 2 43 | #define DRV_CANCEL_SIGNAL 3 44 | #define DRV_FINISH_SIGNAL 4 45 | #define DRV_CREATE_MARKER 5 46 | #define DRV_MARK_SAMPLING 6 47 | #define DRV_MARK_OFF_SAMPLING 7 48 | #define DRV_SET_THREAD_NAME 8 49 | #define DRV_FLUSH_SIGNAL 9 50 | #define DRV_RELEASE_PMU 10 51 | #define DRV_GET_MARKER_ID 11 52 | #define DRV_READ_SIGNAL 12 53 | 54 | #define PAX_CTRL "pax_ctrl" 55 | 56 | /* 57 | * ABSTRACT_Get_Pipe_Name 58 | * Parameters 59 | * void 60 | * 61 | * Returns 62 | * Name of the pipe 63 | * 64 | * Description 65 | * Returns the name of the pipe. The pipe is used for message 66 | * passing during pause, resume, stop and cancel calls. 67 | */ 68 | extern void 69 | ABSTRACT_Get_Pipe_Name (S8 *); 70 | 71 | // Name of the pipe used for Inter-process communication 72 | #define SEP_IPC_PIPE_NAME(arg1) ABSTRACT_Get_Pipe_Name(arg1) 73 | 74 | #define ABSTRACT_NHM_TSC_FREQ_MSR 0xce 75 | 76 | /* 77 | * @fn ABSTRACT_Send_IOCTL (control_code, args) 78 | * 79 | * @param U32 control_code - code for the IOCTL to perform 80 | * @param IOCTL_ARGS args - IOCTL args 81 | * 82 | * @brief Performs the IOCTL specified by the control code and 83 | * returns. Expects to pass IOCTL_ARGS buffer 84 | * 85 | * @return DRV_STATUS - Status Error Code 86 | * 87 | */ 88 | DRV_DLLEXPORT DRV_STATUS 89 | ABSTRACT_Send_IOCTL ( 90 | U32 cmd, 91 | IOCTL_ARGS arg 92 | ); 93 | 94 | 95 | /* 96 | * ABSTRACT_Open_Driver 97 | * Parameters 98 | * NONE 99 | * Returns 100 | * TRUE - if successful or already open 101 | * 102 | * Description 103 | * This function open the driver to perform work. 104 | * 105 | */ 106 | static DRV_STATUS 107 | ABSTRACT_Open_Driver(void); 108 | 109 | /* 110 | * ABSTRACT_Close_Driver 111 | * Parameters 112 | * NONE 113 | * 114 | * Returns 115 | * NONE 116 | * 117 | * Description 118 | * This function close the driver for the current invocation. 119 | * The driver itself will not be unloaded. 120 | * 121 | */ 122 | static VOID 123 | ABSTRACT_Close_Driver(void); 124 | 125 | 126 | #ifdef __cplusplus 127 | } 128 | #endif 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /sepdk/src/inc/pmu_info_struct.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _PMU_INFO_STRUCT_H_INC_ 35 | #define _PMU_INFO_STRUCT_H_INC_ 36 | 37 | // Data Structures for storing entire PMU list 38 | typedef struct PMU_MSR_INFO_NODE_S PMU_MSR_INFO_NODE; 39 | struct PMU_MSR_INFO_NODE_S { 40 | U64 msr_id; 41 | U64 mask; 42 | U16 range; 43 | U16 dynamic; // to be updated 44 | }; 45 | 46 | typedef struct PMU_PCI_INFO_NODE_S PMU_PCI_INFO_NODE; 47 | struct PMU_PCI_INFO_NODE_S { 48 | union { 49 | struct { 50 | U64 bus : 8; 51 | U64 dev : 5; 52 | U64 func : 3; 53 | U64 offset : 16; 54 | U64 rsvd : 32; 55 | } s; 56 | U64 reg; 57 | } u; 58 | }; 59 | 60 | typedef struct PMU_PCI_UNIT_INFO_NODE_S PMU_PCI_UNIT_INFO_NODE; 61 | struct PMU_PCI_UNIT_INFO_NODE_S { 62 | U32 dev; 63 | U32 func; 64 | U16 *reg_offset_list; 65 | }; 66 | 67 | typedef struct PMU_MMIO_BAR_INFO_NODE_S PMU_MMIO_BAR_INFO_NODE; 68 | struct PMU_MMIO_BAR_INFO_NODE_S { 69 | union { 70 | struct { 71 | U32 bus : 8; 72 | U32 dev : 5; 73 | U32 func : 3; 74 | U32 offset : 16; 75 | } s; 76 | U32 reg; 77 | } u; 78 | U8 shift; 79 | U8 bar_prog_type; 80 | U16 reserved; 81 | U64 mask; 82 | }; 83 | 84 | enum { 85 | MMIO_SINGLE_BAR_TYPE = 1, 86 | MMIO_DUAL_BAR_TYPE, 87 | MMIO_DIRECT_BAR_TYPE 88 | }; 89 | 90 | typedef struct PMU_MMIO_UNIT_INFO_NODE_S PMU_MMIO_UNIT_INFO_NODE; 91 | struct PMU_MMIO_UNIT_INFO_NODE_S { 92 | PMU_MMIO_BAR_INFO_NODE primary; 93 | PMU_MMIO_BAR_INFO_NODE secondary; 94 | U32 *reg_offset_list; 95 | }; 96 | 97 | typedef struct PMU_INFO_NODE_S PMU_INFO_NODE; 98 | struct PMU_INFO_NODE_S { 99 | U16 family; 100 | U16 model; 101 | U16 stepping_from; 102 | U16 stepping_to; 103 | PMU_MSR_INFO_NODE **msr_info_list; 104 | PMU_PCI_UNIT_INFO_NODE *pci_info_list; 105 | PMU_MMIO_UNIT_INFO_NODE *mmio_info_list; 106 | }; 107 | 108 | // Data Structure for search operation 109 | typedef struct PMU_SEARCH_NODE_S PMU_SEARCH_NODE; 110 | struct PMU_SEARCH_NODE_S 111 | { 112 | U64 key; // common for MSR/PCI/MMIO 113 | void *addr; // copy address of static node 114 | PMU_SEARCH_NODE *left; 115 | PMU_SEARCH_NODE *right; 116 | U16 height; // For balancing the search tree 117 | U16 range; // For MSR 118 | }; 119 | 120 | #endif 121 | 122 | 123 | -------------------------------------------------------------------------------- /sepdk/src/inc/apic.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _APIC_H_ 34 | #define _APIC_H_ 35 | 36 | #include 37 | #include 38 | 39 | typedef U64 *PHYSICAL_ADDRESS; 40 | /** 41 | // Data Types and Macros 42 | */ 43 | /* 44 | // APIC registers and constants 45 | */ 46 | // APIC base MSR 47 | #define DRV_APIC_BASE_MSR 0x001b 48 | 49 | // APIC registers 50 | #define DRV_APIC_LCL_ID 0x0020 51 | #define DRV_APIC_LCL_TSKPRI 0x0080 52 | #define DRV_APIC_LCL_PPR 0x00a0 53 | #define DRV_APIC_LCL_EOI 0x00b0 54 | #define DRV_APIC_LCL_LDEST 0x00d0 55 | #define DRV_APIC_LCL_DSTFMT 0x00e0 56 | #define DRV_APIC_LCL_SVR 0x00f0 57 | #define DRV_APIC_LCL_ICR 0x0300 58 | #define DRV_APIC_LVT_TIMER 0x0320 59 | #define DRV_APIC_LVT_PMI 0x0340 60 | #define DRV_APIC_LVT_LINT0 0x0350 61 | #define DRV_APIC_LVT_LINT1 0x0360 62 | #define DRV_APIC_LVT_ERROR 0x0370 63 | 64 | #define DRV_APIC_LCL_ID_MSR 0x802 65 | #define DRV_APIC_LCL_TSKPRI_MSR 0x808 66 | #define DRV_APIC_LCL_PPR_MSR 0x80a 67 | #define DRV_APIC_LCL_EOI_MSR 0x80b 68 | #define DRV_APIC_LCL_LDEST_MSR 0x80d 69 | #define DRV_APIC_LCL_DSTFMT_MSR 0x80e 70 | #define DRV_APIC_LCL_SVR_MSR 0x80f 71 | #define DRV_APIC_LCL_ICR_MSR 0x830 72 | #define DRV_APIC_LVT_TIMER_MSR 0x832 73 | #define DRV_APIC_LVT_PMI_MSR 0x834 74 | #define DRV_APIC_LVT_LINT0_MSR 0x835 75 | #define DRV_APIC_LVT_LINT1_MSR 0x836 76 | #define DRV_APIC_LVT_ERROR_MSR 0x837 77 | 78 | // masks for LVT 79 | #define DRV_LVT_MASK 0x10000 80 | #define DRV_LVT_EDGE 0x00000 81 | #define DRV_LVT_LEVEL 0x08000 82 | #define DRV_LVT_EXTINT 0x00700 83 | #define DRV_LVT_NMI 0x00400 84 | 85 | // task priorities 86 | #define DRV_APIC_TSKPRI_LO 0x0000 87 | #define DRV_APIC_TSKPRI_HI 0x00f0 88 | 89 | #define DRV_X2APIC_ENABLED 0xc00LL 90 | 91 | //// Interrupt vector for PMU overflow event 92 | // 93 | // Choose the highest unused IDT vector possible so that our 94 | // callback routine runs at the highest priority allowed; 95 | // must avoid using pre-defined vectors in, 96 | // include/asm/irq.h 97 | // include/asm/hw_irq.h 98 | // include/asm/irq_vectors.h 99 | // 100 | // FIRST_DEVICE_VECTOR should be valid for kernels 2.6.33 and earlier 101 | #define CPU_PERF_VECTOR DRV_LVT_NMI 102 | // Has the APIC Been enabled 103 | #define DRV_APIC_BASE_GLOBAL_ENABLED(a) ((a) & 1 << 11) 104 | #define DRV_APIC_VIRTUAL_WIRE_ENABLED(a) ((a) & 0x100) 105 | 106 | /** 107 | // Function Declarations 108 | */ 109 | 110 | /* 111 | // APIC control functions 112 | */ 113 | extern VOID APIC_Enable_Pmi(VOID); 114 | extern VOID APIC_Init(PVOID param); 115 | extern VOID APIC_Install_Interrupt_Handler(PVOID param); 116 | extern VOID APIC_Restore_LVTPC(PVOID param); 117 | 118 | #endif 119 | 120 | -------------------------------------------------------------------------------- /agentdk/log.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _SEPAGENT_LOG_H_ 30 | #define _SEPAGENT_LOG_H_ 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 37 | 38 | extern FILE *fptr; 39 | extern DRV_BOOL verbose; 40 | 41 | #define SEPAGENT_PRINT_DEBUG(fmt,args...) { \ 42 | if (verbose) { \ 43 | fprintf (stdout, SEPAGENT_MSG_PREFIX " [DEBUG] " fmt,##args); \ 44 | fflush(stdout); \ 45 | } \ 46 | if (fptr != NULL) { \ 47 | fprintf (fptr, SEPAGENT_MSG_PREFIX" [DEBUG] %s [%s/%s:%d] " \ 48 | fmt, __TIME__, __FILENAME__, __func__, __LINE__, ##args); \ 49 | fflush(fptr); \ 50 | } \ 51 | } 52 | 53 | #define SEPAGENT_PRINT(fmt,args...) { \ 54 | fprintf (stdout, SEPAGENT_MSG_PREFIX " " fmt,##args); \ 55 | fflush(stdout); \ 56 | if (fptr != NULL) { \ 57 | fprintf (fptr, SEPAGENT_MSG_PREFIX " %s [%s/%s:%d] " \ 58 | fmt, __TIME__, __FILENAME__, __func__, __LINE__, ##args); \ 59 | fflush(fptr); \ 60 | } \ 61 | } 62 | 63 | #define SEPAGENT_PRINT_WARNING(fmt,args...) { \ 64 | if (verbose) { \ 65 | fprintf (stdout, SEPAGENT_MSG_PREFIX " [WARN] " fmt,##args); \ 66 | fflush(stdout); \ 67 | } \ 68 | if (fptr != NULL) { \ 69 | fprintf (fptr, SEPAGENT_MSG_PREFIX" [WARN] %s [%s/%s:%d] " \ 70 | fmt, __TIME__, __FILENAME__, __func__, __LINE__, ##args); \ 71 | fflush(fptr); \ 72 | } \ 73 | } 74 | 75 | #define SEPAGENT_PRINT_ERROR(fmt,args...) { \ 76 | fprintf (stderr, SEPAGENT_MSG_PREFIX" [ERROR] " fmt, ##args); \ 77 | fflush(stdout); \ 78 | if (fptr != NULL) { \ 79 | fprintf (fptr, SEPAGENT_MSG_PREFIX" [ERROR] %s [%s/%s:%d] " \ 80 | fmt, __TIME__, __FILENAME__, __func__, __LINE__, ##args); \ 81 | fflush(fptr); \ 82 | } \ 83 | } 84 | 85 | #if defined(__cplusplus) 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /tests/operation.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | # 4 | #Permission is hereby granted, free of charge, to any person obtaining a copy 5 | #of this software and associated documentation files (the "Software"), to deal 6 | #in the Software without restriction, including without limitation the rights 7 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | #copies of the Software, and to permit persons to whom the Software is 9 | #furnished to do so, subject to the following conditions: 10 | # 11 | #The above copyright notice and this permission notice shall be included in all 12 | #copies or substantial portions of the Software. 13 | # 14 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | #SOFTWARE. 21 | # 22 | # 23 | # 24 | # 25 | # 26 | # 27 | # 28 | START = 1 # covered 29 | STOP = 2 # covered 30 | INIT_PMU = 3 # covered 31 | INIT = 4 # covered 32 | EM_GROUPS = 5 # covered 33 | SET_CPU_MASK = 17 34 | PCI_READ = 18 35 | PCI_WRITE = 19 36 | READ_PCI_CONFIG = 20 37 | FD_PHYS = 21 38 | WRITE_PCI_CONFIG = 22 39 | INSERT_MARKER = 23 40 | GET_NORMALIZED_TSC = 24 # covered 41 | EM_CONFIG_NEXT = 25 # covered !!!! Hard Coded 42 | SYS_CONFIG = 26 43 | TSC_SKEW_INFO = 27 # TODO 44 | NUM_CORES = 28 # covered 45 | COLLECT_SYS_CONFIG = 29 # covered 46 | GET_SYS_CONFIG = 30 # covered 47 | PAUSE = 31 48 | RESUME = 32 49 | SET_ASYNC_EVENT = 33 50 | ASYNC_STOP = 34 51 | TERMINATE = 35 # covered 52 | READ_MSRS = 36 53 | LBR_INFO = 37 54 | RESERVE = 38 # covered 55 | MARK = 39 56 | AWAIT_STOP = 40 57 | SEED_NAME = 41 58 | KERNEL_CS = 42 59 | SET_UID = 43 60 | VERSION = 51 # covered 61 | CHIPSET_INIT = 52 62 | GET_CHIPSET_DEVICE_ID = 53 63 | SWITCH_GROUP = 54 64 | GET_NUM_CORE_CTRS = 55 65 | PWR_INFO = 56 66 | NUM_DESCRIPTOR = 57 # covered 67 | DESC_NEXT = 58 # covered 68 | MARK_OFF = 59 69 | CREATE_MARKER = 60 70 | GET_DRIVER_STATE = 61 71 | READ_SWITCH_GROUP = 62 72 | EM_GROUPS_UNC = 63 # covered 73 | EM_CONFIG_NEXT_UNC = 64 # hard coded 74 | INIT_UNC = 65 # covered 75 | RO_INFO = 66 76 | READ_MSR = 67 77 | WRITE_MSR = 68 78 | THREAD_SET_NAME = 69 79 | GET_PLATFORM_INFO = 70 # covered 80 | GET_NORMALIZED_TSC_STANDALONE = 71 81 | READ_AND_RESET = 72 82 | SET_CPU_TOPOLOGY = 73 # covered 83 | INIT_NUM_DEV = 74 # covered 84 | SET_GFX_EVENT = 75 85 | GET_NUM_SAMPLES = 76 # covered 86 | SET_PWR_EVENT = 77 87 | SET_DEVICE_NUM_UNITS = 78 # covered 88 | TIMER_TRIGGER_READ = 79 89 | GET_INTERVAL_COUNTS = 80 90 | FLUSH = 81 91 | SET_SCAN_UNCORE_TOPOLOGY_INFO = 82 92 | GET_UNCORE_TOPOLOGY = 83 93 | GET_MARKER_ID = 84 94 | GET_SAMPLE_DROP_INFO = 85 # covered 95 | GET_DRV_SETUP_INFO = 86 # covered 96 | GET_PLATFORM_TOPOLOGY = 87 97 | GET_THREAD_COUNT = 88 # covered 98 | GET_THREAD_INFO = 89 # covered 99 | GET_DRIVER_LOG = 90 100 | CONTROL_DRIVER_LOG = 91 101 | SET_OSID = 92 102 | GET_AGENT_MODE = 93 103 | INIT_DRIVER = 94 104 | SET_EMON_BUFFER_DRIVER_HELPER = 95 105 | -------------------------------------------------------------------------------- /sepdk/src/inc/pmu_list.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _PMU_LIST_H_INC_ 35 | #define _PMU_LIST_H_INC_ 36 | 37 | 38 | extern U32 drv_type; 39 | 40 | /************************************************************/ 41 | /* 42 | * PMU list API for checking valid PMU list 43 | * 44 | ************************************************************/ 45 | 46 | /*! 47 | * @fn DRV_BOOL PMU_LIST_Check_MSR (U32) 48 | * 49 | * @brief Search the MSR address in the list 50 | * 51 | * @param MSR address to be checked 52 | * 53 | * @return TRUE if the MSR address is found in the list, 54 | * FALSE otherwise 55 | */ 56 | extern DRV_BOOL 57 | PMU_LIST_Check_MSR ( 58 | U32 msr_id 59 | ); 60 | 61 | 62 | /*! 63 | * @fn DRV_BOOL PMU_LIST_Check_PCI (U8, U8, U8, U32) 64 | * 65 | * @brief Search the PCI programming info in the list 66 | * 67 | * @param bus_id - PCI bus id 68 | * device_id - PCI device id 69 | * func_id - PCI function id 70 | * offset - PCI offset 71 | * 72 | * @return TRUE if the PCI information is found in the list, 73 | * FALSE otherwise 74 | */ 75 | extern DRV_BOOL 76 | PMU_LIST_Check_PCI ( 77 | U8 bus_id, 78 | U8 device_id, 79 | U8 func_id, 80 | U32 offset 81 | ); 82 | 83 | 84 | /*! 85 | * @fn DRV_BOOL PMU_LIST_Check_MMIO (PMU_MMIO_BAR_INFO_NODE, 86 | * PMU_MMIO_BAR_INFO_NODE, 87 | * U32) 88 | * 89 | * @brief Search the MMIO programming info in the list 90 | * 91 | * @param primary - pimary MMIO BAR programming info 92 | * secondary - secondary MMIO BAR programming info 93 | * offset - MMIO offset 94 | * 95 | * @return TRUE if the MMIO information is found in the list, 96 | * FALSE otherwise 97 | */ 98 | extern DRV_BOOL 99 | PMU_LIST_Check_MMIO ( 100 | PMU_MMIO_BAR_INFO_NODE primary, 101 | PMU_MMIO_BAR_INFO_NODE secondary, 102 | U32 offset 103 | ); 104 | 105 | 106 | /*! 107 | * @fn OS_STATUS PMU_LIST_Initialize (S32 *) 108 | * @brief Detect the CPU id and locate the applicable PMU list 109 | * 110 | * @param index value of the whitelist. -1 if not found. 111 | * 112 | * @return OS_SUCCESS 113 | */ 114 | extern OS_STATUS 115 | PMU_LIST_Initialize ( 116 | S32 *idx 117 | ); 118 | 119 | 120 | /*! 121 | * @fn OS_STATUS PMU_LIST_Build_MSR_List (void) 122 | * @brief Build the MSR search tree 123 | * 124 | * @param None 125 | * 126 | * @return OS_SUCCESS 127 | */ 128 | extern OS_STATUS 129 | PMU_LIST_Build_MSR_List ( 130 | void 131 | ); 132 | 133 | /*! 134 | * @fn OS_STATUS PMU_LIST_Build_PCI_List (void) 135 | * @brief Build the PCI search tree 136 | * 137 | * @param None 138 | * 139 | * @return OS_SUCCESS 140 | */ 141 | extern OS_STATUS 142 | PMU_LIST_Build_PCI_List ( 143 | void 144 | ); 145 | 146 | /*! 147 | * @fn OS_STATUS PMU_LIST_Build_MMIO_List (void) 148 | * @brief Build the MMIO search tree 149 | * 150 | * @param None 151 | * 152 | * @return OS_SUCCESS 153 | */ 154 | extern OS_STATUS 155 | PMU_LIST_Build_MMIO_List ( 156 | void 157 | ); 158 | 159 | /*! 160 | * @fn OS_STATUS PMU_LIST_Clean_Up (void) 161 | * @brief Clean up all the search trees 162 | * 163 | * @param None 164 | * 165 | * @return OS_SUCCESS 166 | */ 167 | extern OS_STATUS 168 | PMU_LIST_Clean_Up ( 169 | void 170 | ); 171 | 172 | #endif 173 | 174 | -------------------------------------------------------------------------------- /sepdk/src/sys64.S: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2002-2019 Intel Corporation. All Rights Reserved. 2 | # 3 | # This file is part of SEP Development Kit 4 | # 5 | # SEP Development Kit is free software; you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # version 2 as published by the Free Software Foundation. 8 | # 9 | # SEP Development Kit is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with SEP Development Kit; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | # As a special exception, you may use this file as part of a free software 19 | # library without restriction. Specifically, if other files instantiate 20 | # templates or use macros or inline functions from this file, or you compile 21 | # this file and link it with other files to produce an executable, this 22 | # file does not by itself cause the resulting executable to be covered by 23 | # the GNU General Public License. This exception does not however 24 | # invalidate any other reasons why the executable file might be covered by 25 | # the GNU General Public License. 26 | 27 | #include "inc/asm_helper.h" 28 | #include 29 | #include 30 | 31 | .text 32 | 33 | 34 | #*********************************************************************** 35 | # 36 | # SYS_Get_GDT_Base 37 | # Get the GDT Desc address 38 | # 39 | # Entry: pointer to location to store gdt Desc 40 | # 41 | # Exit: none 42 | # 43 | # void SYS_Get_GDT_Base(U64 *pGdtDesc); 44 | # 45 | #*********************************************************************** 46 | .global SYS_Get_GDT_Base 47 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) 48 | SYM_FUNC_START(SYS_Get_GDT_Base) 49 | #else 50 | ENTRY(SYS_Get_GDT_Base) 51 | #endif 52 | SGDT (%rdi) 53 | ret 54 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) 55 | SYM_FUNC_END(SYS_Get_GDT_Base) 56 | #else 57 | ENDPROC(SYS_Get_GDT_Base) 58 | #endif 59 | 60 | #*********************************************************************** 61 | # 62 | # SYS_Get_TSC 63 | # Get the current TSC 64 | # 65 | # Entry: pointer to location to store gdt Desc 66 | # 67 | # Exit: none 68 | # 69 | # void SYS_Get_TSC(U64 *tsc); 70 | # 71 | #*********************************************************************** 72 | # .global SYS_Get_TSC 73 | #SYS_Get_TSC: 74 | # rdtsc 75 | # ret 76 | 77 | #*********************************************************************** 78 | # 79 | # SYS_IO_Delay 80 | # Add a short delay to the instruction stream 81 | # 82 | # Entry: none 83 | # 84 | # Exit: none 85 | # 86 | # void SYS_IO_Delay(void); 87 | # 88 | #*********************************************************************** 89 | .global SYS_IO_Delay 90 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) 91 | SYM_FUNC_START(SYS_IO_Delay) 92 | #else 93 | ENTRY(SYS_IO_Delay) 94 | #endif 95 | ret 96 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0) 97 | SYM_FUNC_END(SYS_IO_Delay) 98 | #else 99 | ENDPROC(SYS_IO_Delay) 100 | #endif 101 | 102 | # ---------------------------------------------------------------------------- 103 | # name: SYS_PerfVec_Handler 104 | # 105 | # description: ISR entry for local APIC PERF interrupt vector 106 | # 107 | # Input: n/a 108 | # 109 | # Output: n/a 110 | # ---------------------------------------------------------------------------- 111 | 112 | .global SYS_Perfvec_Handler 113 | SYS_Perfvec_Handler: 114 | CFI_STARTPROC 115 | pushq %rax // fake an error code... 116 | cld // cause the kernel likes it this way... 117 | 118 | SAVE_ALL // Save the world! 119 | 120 | movl $MSR_GS_BASE,%ecx // for the moment, do the safe swapgs check 121 | rdmsr 122 | xorl %ebx,%ebx // assume no swapgs (ebx == 0) 123 | testl %edx,%edx 124 | js 1f 125 | swapgs 126 | movl $1,%ebx // ebx == 1 means we did a swapgs 127 | 1: movq %rsp,%rdi // pt_regs is the first argument 128 | 129 | // 130 | // ebx is zero if no swap, one if swap 131 | // ebx is preserved in C calling convention... 132 | // 133 | // NOTE: the C code is responsible for ACK'ing the APIC!!! 134 | // 135 | call PMI_Interrupt_Handler 136 | 137 | // 138 | // Don't want an interrupt while we are doing the swapgs stuff 139 | // 140 | cli 141 | testl %ebx,%ebx 142 | jz 2f 143 | swapgs 144 | 2: RESTORE_ALL 145 | popq %rax 146 | iretq 147 | CFI_ENDPROC 148 | -------------------------------------------------------------------------------- /sepdk/src/inc/output.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _OUTPUT_H_ 34 | #define _OUTPUT_H_ 35 | 36 | #include 37 | #include 38 | 39 | /* 40 | * Initial allocation 41 | * Size of buffer = 512KB (2^19) 42 | * number of buffers = 2 43 | * The max size of the buffer cannot exceed 1<<22 i.e. 4MB 44 | */ 45 | #define OUTPUT_SMALL_BUFFER (1<<15) 46 | #define OUTPUT_LARGE_BUFFER (1<<19) 47 | #define OUTPUT_CP_BUFFER (1<<22) 48 | #define OUTPUT_EMON_BUFFER (1<<25) 49 | #define OUTPUT_MEMORY_THRESHOLD 0x8000000 50 | 51 | extern U32 output_buffer_size; 52 | extern U32 saved_buffer_size; 53 | #define OUTPUT_BUFFER_SIZE output_buffer_size 54 | #define OUTPUT_NUM_BUFFERS 2 55 | #if defined (DRV_ANDROID) 56 | #define MODULE_BUFF_SIZE 1 57 | #else 58 | #define MODULE_BUFF_SIZE 2 59 | #endif 60 | 61 | 62 | /* 63 | * Data type declarations and accessors macros 64 | */ 65 | typedef struct { 66 | spinlock_t buffer_lock; 67 | U32 remaining_buffer_size; 68 | U32 current_buffer; 69 | U32 total_buffer_size; 70 | U32 next_buffer[OUTPUT_NUM_BUFFERS]; 71 | U32 buffer_full[OUTPUT_NUM_BUFFERS]; 72 | U8 *buffer[OUTPUT_NUM_BUFFERS]; 73 | U32 signal_full; 74 | DRV_BOOL tasklet_queued; 75 | } OUTPUT_NODE, *OUTPUT; 76 | 77 | #define OUTPUT_buffer_lock(x) (x)->buffer_lock 78 | #define OUTPUT_remaining_buffer_size(x) (x)->remaining_buffer_size 79 | #define OUTPUT_total_buffer_size(x) (x)->total_buffer_size 80 | #define OUTPUT_buffer(x,y) (x)->buffer[(y)] 81 | #define OUTPUT_buffer_full(x,y) (x)->buffer_full[(y)] 82 | #define OUTPUT_current_buffer(x) (x)->current_buffer 83 | #define OUTPUT_signal_full(x) (x)->signal_full 84 | #define OUTPUT_tasklet_queued(x) (x)->tasklet_queued 85 | /* 86 | * Add an array of control buffer for per-cpu 87 | */ 88 | typedef struct { 89 | wait_queue_head_t queue; 90 | OUTPUT_NODE outbuf; 91 | U32 sample_count; 92 | } BUFFER_DESC_NODE, *BUFFER_DESC; 93 | 94 | #define BUFFER_DESC_queue(a) (a)->queue 95 | #define BUFFER_DESC_outbuf(a) (a)->outbuf 96 | #define BUFFER_DESC_sample_count(a) (a)->sample_count 97 | 98 | extern BUFFER_DESC cpu_buf; // actually an array of BUFFER_DESC_NODE 99 | extern BUFFER_DESC unc_buf; 100 | extern BUFFER_DESC module_buf; 101 | extern BUFFER_DESC cpu_sideband_buf; 102 | extern BUFFER_DESC emon_buf; 103 | /* 104 | * Interface Functions 105 | */ 106 | 107 | extern int OUTPUT_Module_Fill (PVOID data, U16 size, U8 in_notification); 108 | extern OS_STATUS OUTPUT_Initialize (void); 109 | extern OS_STATUS OUTPUT_Initialize_UNC (void); 110 | extern OS_STATUS OUTPUT_Initialize_EMON (void); 111 | extern void OUTPUT_Cleanup (VOID); 112 | extern void OUTPUT_Cleanup (VOID); 113 | extern int OUTPUT_Destroy (VOID); 114 | extern int OUTPUT_Flush (VOID); 115 | extern int OUTPUT_Flush_EMON (VOID); 116 | extern ssize_t OUTPUT_Module_Read (struct file *filp, char *buf, size_t count, loff_t *f_pos); 117 | extern ssize_t OUTPUT_Sample_Read (struct file *filp, char *buf, size_t count, loff_t *f_pos); 118 | extern ssize_t OUTPUT_UncSample_Read (struct file *filp, char *buf, size_t count, loff_t *f_pos); 119 | extern ssize_t OUTPUT_SidebandInfo_Read (struct file *filp, char *buf, size_t count, loff_t *f_pos); 120 | extern ssize_t OUTPUT_Emon_Read (struct file *filp, char *buf, size_t count, loff_t *f_pos); 121 | extern void* OUTPUT_Reserve_Buffer_Space (BUFFER_DESC bd, U32 size, DRV_BOOL defer, U8 in_notification); 122 | extern void* OUTPUT_Get_Buffer (BUFFER_DESC bd); 123 | 124 | #endif 125 | 126 | -------------------------------------------------------------------------------- /sepdk/src/inc/pmu_info_mmio.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _PMU_INFO_MMIO_H_INC_ 35 | #define _PMU_INFO_MMIO_H_INC_ 36 | /* Public */ 37 | 38 | static U32 mmio_client_imc_common_offset[] = { 39 | 0x5040, 0x5044, 0x5048, 0x5050, 0x5054, 0x5058, 0 40 | }; 41 | 42 | static U32 mmio_fpga_common_offset[] = { 43 | 0x3008, 0x3010, 0x3018, 0x3020, 0x3028, 0x1008, 0x1010, 0x1018, 0x2008, 44 | 0 45 | }; 46 | 47 | static U32 mmio_hfi_common_offset[] = { 48 | 0x500, 0x508, 0x400, 0x408, 0x418, 0x420, 0x428, 0x430, 0x438, 0x440, 49 | 0x448, 0x450, 0x458, 0x460, 0x468, 0x470, 0x478, 0x480, 0x488, 0x490, 50 | 0x498, 0x4a0, 0 51 | }; 52 | 53 | static U32 mmio_bxt_dvt_imc_offset[] = { 54 | 0x6868, 0x686C, 0 55 | }; 56 | 57 | static U32 mmio_dual_bar_imc_offset[] = { 58 | 0x22800, 0x26800, 0x22840, 0x22844, 0x22848, 0x2284c, 0x22850, 0x26840, 0x26844, 59 | 0x26848, 0x2684c, 0x26850, 0x2285c, 0x2685c, 0x22808, 0x22810, 0x22818, 0x22820, 60 | 0x22828, 0x26808, 0x26810, 0x26818, 0x26820, 0x26828, 0x22854, 0x26854, 0x22838, 61 | 0x26838, 0x2290, 0x2298, 0x22A0, 0x22A8, 0x22B0, 0x4000, 0x8, 0x40, 0x4008, 62 | 0x4040, 0x4044, 0x54, 0x4054, 0x4038, 0x38, 0xF8, 0x44, 0x48, 0x10, 0x4010, 63 | 0x2290, 0x4C, 0x4048, 0x404C, 0x18, 0x20, 0x4018, 0x4020, 0 64 | }; 65 | 66 | 67 | static PMU_MMIO_UNIT_INFO_NODE client_common_mmio_list[] = { 68 | { 69 | {{{0, 0, 0, 0x48}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0007FFFFF8000ULL}, 70 | {{{0, 0, 0, 0}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0}, 71 | mmio_client_imc_common_offset 72 | }, 73 | { 74 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 75 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 76 | NULL 77 | } 78 | }; 79 | 80 | static PMU_MMIO_UNIT_INFO_NODE skx_mmio_list[] = { 81 | { 82 | {{{0, 0, 0, 0x10}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x3FFFFFFF8000ULL}, 83 | {{{0, 0, 0, 0}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0}, 84 | mmio_fpga_common_offset 85 | }, 86 | { 87 | {{{0, 0, 0, 0x10}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x3ffffffff0000ULL}, 88 | {{{0, 0, 0, 0}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0}, 89 | mmio_hfi_common_offset 90 | }, 91 | { 92 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 93 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 94 | NULL 95 | } 96 | }; 97 | 98 | static PMU_MMIO_UNIT_INFO_NODE server_common_mmio_list[] = { 99 | { 100 | {{{0, 0, 0, 0x10}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x3ffffffff0000ULL}, 101 | {{{0, 0, 0, 0}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0}, 102 | mmio_hfi_common_offset 103 | }, 104 | { 105 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 106 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 107 | NULL 108 | } 109 | }; 110 | 111 | static PMU_MMIO_UNIT_INFO_NODE bxt_dvt_mmio_info_list[] = { 112 | { 113 | {{{0, 0, 0, 0x48}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0007FFFFF8000LL}, 114 | {{{0, 0, 0, 0}}, 0, MMIO_SINGLE_BAR_TYPE, 0, 0x0}, 115 | mmio_bxt_dvt_imc_offset 116 | }, 117 | { 118 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 119 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 120 | NULL 121 | } 122 | }; 123 | 124 | static PMU_MMIO_UNIT_INFO_NODE snr_mmio_info_list[] = { 125 | { 126 | {{{0, 0, 1, 0xD0}}, 23, MMIO_DUAL_BAR_TYPE, 0, 0x1FFFFFFFULL}, 127 | {{{0, 0, 1, 0xD8}}, 12, MMIO_DUAL_BAR_TYPE, 0, 0x7FFULL}, 128 | mmio_dual_bar_imc_offset 129 | }, 130 | { 131 | {{{0, 0, 1, 0xD0}}, 23, MMIO_DUAL_BAR_TYPE, 0, 0x1FFFFFFFULL}, 132 | {{{0, 0, 1, 0xDC}}, 12, MMIO_DUAL_BAR_TYPE, 0, 0x7FFULL}, 133 | mmio_dual_bar_imc_offset 134 | }, 135 | { 136 | {{{0, 0, 0, 0x0}}, 0, MMIO_DUAL_BAR_TYPE, 0, 0x0}, 137 | {{{0, 0, 0, 0x0}}, 0, MMIO_DUAL_BAR_TYPE, 0, 0x0}, 138 | mmio_dual_bar_imc_offset 139 | }, 140 | { 141 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 142 | {{{0, 0, 0, 0}}, 0, 0, 0, 0x0}, 143 | NULL 144 | } 145 | }; 146 | 147 | #endif 148 | 149 | -------------------------------------------------------------------------------- /sepdk/src/inc/pmu_info.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #ifndef _PMU_INFO_H_INC_ 35 | #define _PMU_INFO_H_INC_ 36 | 37 | U32 drv_type = DRV_TYPE_PUBLIC; 38 | S8 *drv_type_str = "PUBLIC"; 39 | 40 | static const PMU_INFO_NODE pmu_info_list[] = { 41 | // CTI_Broadwell_Server = 0x406F0 42 | {0x6, 0x4F, 0x0, 0xF, bdx_msr_list, bdx_pci_list, skx_mmio_list}, 43 | 44 | // CTI_Skylake = 0x506E0 45 | {0x6, 0x5E, 0x0, 0xF, skl_msr_list, NULL, client_common_mmio_list}, 46 | 47 | // CTI_Skylake_ULT = 0x406E0 48 | {0x6, 0x4E, 0x0, 0xF, skl_msr_list, NULL, client_common_mmio_list}, 49 | 50 | // CTI_Kabylake = 0x906E0 51 | {0x6, 0x9E, 0x0, 0x9, skl_msr_list, NULL, client_common_mmio_list}, 52 | 53 | // CTI_Kabylake_ULX = 0x806E0 54 | {0x6, 0x8E, 0x0, 0xF, skl_msr_list, NULL, client_common_mmio_list}, 55 | 56 | // CTI_Skylake_Server = 0x50650 57 | {0x6, 0x55, 0x0, 0x4, skx_msr_list, skx_pci_list, skx_mmio_list}, 58 | 59 | // CTI_Coffeelake = 0x906E0 60 | {0x6, 0x9E, 0xA, 0xF, skl_msr_list, NULL, client_common_mmio_list}, 61 | 62 | // CTI_Cascadelake_Server = 0x50655 63 | {0x6, 0x55, 0x5, 0x9, clx_msr_list, skx_pci_list, server_common_mmio_list}, 64 | 65 | // CTI_Snowridge = 0x80660 66 | {0x6, 0x86, 0x0, 0xF, snr_msr_list, snr_pci_list, snr_mmio_info_list}, 67 | 68 | // CTI_Icelake = 0x706E0 69 | {0x6, 0x7E, 0x0, 0xF, icl_msr_list, NULL, client_common_mmio_list}, 70 | 71 | // CTI_Geminilake = 0x706A0 72 | {0x6, 0x7A, 0x0, 0xF, gml_msr_list, NULL, NULL}, 73 | 74 | // CTI_CougarMountain = 0x606E0 75 | {0x6, 0x6E, 0x0, 0xF, slm_msr_list, NULL, NULL}, 76 | 77 | // CTI_Denverton = 0x506F0 78 | {0x6, 0x5F, 0x0, 0xF, dnv_msr_list, NULL, bxt_dvt_mmio_info_list}, 79 | 80 | // CTI_Broxton = 0x506C0 81 | {0x6, 0x5C, 0x0, 0xF, bxt_msr_list, NULL, bxt_dvt_mmio_info_list}, 82 | 83 | // CTI_Broadwell_DE = 0x50660 84 | {0x6, 0x56, 0x0, 0xF, bdx_msr_list, bdw_de_pci_list, client_common_mmio_list}, 85 | 86 | // CTI_Broadwell_H = 0x40670 87 | {0x6, 0x47, 0x0, 0xF, hsw_msr_list, NULL, client_common_mmio_list}, 88 | 89 | // CTI_Knightslanding = 0x50670 90 | {0x6, 0x57, 0x0, 0xF, knl_msr_list, knl_pci_list, server_common_mmio_list}, 91 | 92 | // CTI_Knightsmill = 0x80650 93 | {0x6, 0x85, 0x0, 0xF, knl_msr_list, knl_pci_list, server_common_mmio_list}, 94 | 95 | // CTI_Anniedale = 0x506A0 96 | {0x6, 0x5A, 0x0, 0xF, and_msr_list, NULL, NULL}, 97 | 98 | // CTI_Cherryview = 0x406C0 99 | {0x6, 0x4C, 0x0, 0xF, slm_msr_list, NULL, NULL}, 100 | 101 | // CTI_Tangier = 0x406A0 102 | {0x6, 0x4A, 0x0, 0xF, slm_msr_list, NULL, NULL}, 103 | 104 | // CTI_Haswell_Server = 0x306F0 105 | {0x6, 0x3F, 0x0, 0xF, hsx_msr_list, hsx_pci_list, server_common_mmio_list}, 106 | 107 | // CTI_Broadwell = 0x306D0 108 | {0x6, 0x3D, 0x0, 0xF, hsw_msr_list, NULL, client_common_mmio_list}, 109 | 110 | // CTI_Avoton = 0x406D0 111 | {0x6, 0x4D, 0x0, 0xF, avt_msr_list, NULL, NULL}, 112 | 113 | // CTI_Crystalwell = 0x40660 114 | {0x6, 0x46, 0x0, 0xF, hsw_msr_list, NULL, client_common_mmio_list}, 115 | 116 | // CTI_Haswell_ULT = 0x40650 117 | {0x6, 0x45, 0x0, 0xF, hsw_ult_msr_list, NULL, client_common_mmio_list}, 118 | 119 | // CTI_Ivytown = 0x306E0 120 | {0x6, 0x3E, 0x0, 0xF, ivt_msr_list, ivt_pci_list, server_common_mmio_list}, 121 | 122 | // CTI_Silvermont = 0x30670 123 | {0x6, 0x37, 0x0, 0xF, slm_msr_list, NULL, NULL}, 124 | 125 | // CTI_Haswell = 0x306c0 126 | {0x6, 0x3C, 0x0, 0xF, hsw_msr_list, NULL, client_common_mmio_list}, 127 | 128 | // CTI_Ivybridge = 0x306a0 129 | {0x6, 0x3A, 0x0, 0xF, snb_msr_list, NULL, client_common_mmio_list}, 130 | 131 | // CTI_Jaketown = 0x206d0 132 | {0x6, 0x2D, 0x0, 0xF, jkt_msr_list, jkt_pci_list, server_common_mmio_list}, 133 | 134 | // CTI_Sandybridge = 0x206a0 135 | {0x6, 0x2A, 0x0, 0xF, snb_msr_list, NULL, client_common_mmio_list}, 136 | 137 | // CTI_Cometlake = 0xA0660 138 | {0x6, 0xA6, 0x0, 0xF, skl_msr_list, NULL, client_common_mmio_list}, 139 | 140 | // Last 141 | {0x0, 0x0, 0x0, 0x0, NULL, NULL, NULL} 142 | }; 143 | 144 | #endif 145 | 146 | 147 | -------------------------------------------------------------------------------- /agentdk/include/lwpmudrv_version.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | /* 30 | * File : lwpmudrv_version.h 31 | */ 32 | 33 | #ifndef _LWPMUDRV_VERSION_H_ 34 | #define _LWPMUDRV_VERSION_H_ 35 | 36 | #define _STRINGIFY(x) #x 37 | #define STRINGIFY(x) _STRINGIFY(x) 38 | #define _STRINGIFY_W(x) L#x 39 | #define STRINGIFY_W(x) _STRINGIFY_W(x) 40 | 41 | #define SEP_MAJOR_VERSION 5 42 | #define SEP_MINOR_VERSION 17 43 | #define SEP_API_VERSION 5 // API version is independent of major/minor and tracks driver version 44 | 45 | #define SEP_PREV_MAJOR_VERSION 5 46 | #define EMON_PREV_MAJOR_VERSION 11 47 | 48 | #define SEP_RELEASE_STRING "Beta" 49 | 50 | #define EMON_MAJOR_VERSION 11 51 | #define EMON_MINOR_VERSION SEP_MINOR_VERSION 52 | #define EMON_PRODUCT_RELEASE_STRING SEP_RELEASE_STRING 53 | 54 | #if defined(SEP_ENABLE_PRIVATE_CPUS) 55 | #define PRODUCT_TYPE "private" 56 | #define SEP_NAME "sepint" 57 | #define SEP_NAME_W L"sepint" 58 | #else 59 | #if defined(SEP_ENABLE_NDA_CPUS) 60 | #define PRODUCT_TYPE "NDA" 61 | #else 62 | #define PRODUCT_TYPE "public" 63 | #endif 64 | #define SEP_NAME "sep" 65 | #define SEP_NAME_W L"sep" 66 | #endif 67 | 68 | #if !defined(PRODUCT_BUILDER) 69 | #define PRODUCT_BUILDER unknown 70 | #endif 71 | 72 | 73 | #define TB_FILE_EXT ".tb7" 74 | #define TB_FILE_EXT_W L".tb7" 75 | 76 | #define SEP_PRODUCT_NAME "Sampling Enabling Product" 77 | #define EMON_PRODUCT_NAME "EMON" 78 | 79 | #define PRODUCT_VERSION_DATE __DATE__ " at " __TIME__ 80 | 81 | #define SEP_PRODUCT_COPYRIGHT "Copyright(C) 2007-2019 Intel Corporation. All rights reserved." 82 | #define EMON_PRODUCT_COPYRIGHT "Copyright(C) 1993-2019 Intel Corporation. All rights reserved." 83 | 84 | #define PRODUCT_DISCLAIMER "Warning: This computer program is protected under U.S. and international\ncopyright laws, and may only be used or copied in accordance with the terms\nof the license agreement. Except as permitted by such license, no part\nof this computer program may be reproduced, stored in a retrieval system,\nor transmitted in any form or by any means without the express written consent\nof Intel Corporation." 85 | #define PRODUCT_VERSION STRINGIFY(SEP_MAJOR_VERSION) "." STRINGIFY(SEP_MINOR_VERSION) 86 | 87 | #define SEP_MSG_PREFIX SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) "_" STRINGIFY(SEP_MINOR_VERSION) ":" 88 | #define SEP_VERSION_STR STRINGIFY(SEP_MAJOR_VERSION) "." STRINGIFY(SEP_MINOR_VERSION) 89 | 90 | #if defined(DRV_OS_WINDOWS) 91 | 92 | #define SEP_DRIVER_NAME SEP_NAME "drv" STRINGIFY(SEP_MAJOR_VERSION) 93 | #define SEP_DRIVER_NAME_W SEP_NAME_W L"drv" STRINGIFY_W(SEP_MAJOR_VERSION) 94 | #define SEP_DEVICE_NAME SEP_DRIVER_NAME 95 | 96 | #define SEP_PREV_DRIVER_NAME SEP_NAME "drv" STRINGIFY(SEP_PREV_MAJOR_VERSION) 97 | #define SEP_PREV_DRIVER_NAME_W SEP_NAME_W L"drv" STRINGIFY_W(SEP_PREV_MAJOR_VERSION) 98 | #define SEP_PREV_DEVICE_NAME SEP_PREV_DRIVER_NAME 99 | 100 | #endif 101 | 102 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 103 | 104 | #define SEP_DRIVER_NAME SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) 105 | #define SEP_SAMPLES_NAME SEP_DRIVER_NAME "_s" 106 | #define SEP_UNCORE_NAME SEP_DRIVER_NAME "_u" 107 | #define SEP_SIDEBAND_NAME SEP_DRIVER_NAME "_b" 108 | #define SEP_EMON_NAME SEP_DRIVER_NAME "_e" 109 | #define SEP_DEVICE_NAME "/dev/" SEP_DRIVER_NAME 110 | 111 | #define SEP_PREV_DRIVER_NAME SEP_NAME STRINGIFY(SEP_PREV_MAJOR_VERSION) 112 | #define SEP_PREV_SAMPLES_NAME SEP_PREV_DRIVER_NAME "_s" 113 | #define SEP_PREV_UNCORE_NAME SEP_PREV_DRIVER_NAME "_u" 114 | #define SEP_PREV_SIDEBAND_NAME SEP_PREV_DRIVER_NAME "_b" 115 | #define SEP_PREV_DEVICE_NAME "/dev/" SEP_PREV_DRIVER_NAME 116 | 117 | #endif 118 | 119 | #if defined(DRV_OS_MAC) 120 | 121 | #define SEP_DRIVER_NAME SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) 122 | #define SEP_SAMPLES_NAME SEP_DRIVER_NAME "_s" 123 | #define SEP_DEVICE_NAME SEP_DRIVER_NAME 124 | 125 | #define SEP_PREV_DRIVER_NAME SEP_NAME STRINGIFY(SEP_PREV_MAJOR_VERSION) 126 | #define SEP_PREV_SAMPLES_NAME SEP_PREV_DRIVER_NAME "_s" 127 | #define SEP_PREV_DEVICE_NAME SEP_PREV_DRIVER_NAME 128 | 129 | #endif 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /sepdk/include/lwpmudrv_version.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | /* 30 | * File : lwpmudrv_version.h 31 | */ 32 | 33 | #ifndef _LWPMUDRV_VERSION_H_ 34 | #define _LWPMUDRV_VERSION_H_ 35 | 36 | #define _STRINGIFY(x) #x 37 | #define STRINGIFY(x) _STRINGIFY(x) 38 | #define _STRINGIFY_W(x) L#x 39 | #define STRINGIFY_W(x) _STRINGIFY_W(x) 40 | 41 | #define SEP_MAJOR_VERSION 5 42 | #define SEP_MINOR_VERSION 17 43 | #define SEP_API_VERSION 5 // API version is independent of major/minor and tracks driver version 44 | 45 | #define SEP_PREV_MAJOR_VERSION 5 46 | #define EMON_PREV_MAJOR_VERSION 11 47 | 48 | #define SEP_RELEASE_STRING "Beta" 49 | 50 | #define EMON_MAJOR_VERSION 11 51 | #define EMON_MINOR_VERSION SEP_MINOR_VERSION 52 | #define EMON_PRODUCT_RELEASE_STRING SEP_RELEASE_STRING 53 | 54 | #if defined(SEP_ENABLE_PRIVATE_CPUS) 55 | #define PRODUCT_TYPE "private" 56 | #define SEP_NAME "sepint" 57 | #define SEP_NAME_W L"sepint" 58 | #else 59 | #if defined(SEP_ENABLE_NDA_CPUS) 60 | #define PRODUCT_TYPE "NDA" 61 | #else 62 | #define PRODUCT_TYPE "public" 63 | #endif 64 | #define SEP_NAME "sep" 65 | #define SEP_NAME_W L"sep" 66 | #endif 67 | 68 | #if !defined(PRODUCT_BUILDER) 69 | #define PRODUCT_BUILDER unknown 70 | #endif 71 | 72 | 73 | #define TB_FILE_EXT ".tb7" 74 | #define TB_FILE_EXT_W L".tb7" 75 | 76 | #define SEP_PRODUCT_NAME "Sampling Enabling Product" 77 | #define EMON_PRODUCT_NAME "EMON" 78 | 79 | #define PRODUCT_VERSION_DATE __DATE__ " at " __TIME__ 80 | 81 | #define SEP_PRODUCT_COPYRIGHT "Copyright(C) 2007-2019 Intel Corporation. All rights reserved." 82 | #define EMON_PRODUCT_COPYRIGHT "Copyright(C) 1993-2019 Intel Corporation. All rights reserved." 83 | 84 | #define PRODUCT_DISCLAIMER "Warning: This computer program is protected under U.S. and international\ncopyright laws, and may only be used or copied in accordance with the terms\nof the license agreement. Except as permitted by such license, no part\nof this computer program may be reproduced, stored in a retrieval system,\nor transmitted in any form or by any means without the express written consent\nof Intel Corporation." 85 | #define PRODUCT_VERSION STRINGIFY(SEP_MAJOR_VERSION) "." STRINGIFY(SEP_MINOR_VERSION) 86 | 87 | #define SEP_MSG_PREFIX SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) "_" STRINGIFY(SEP_MINOR_VERSION) ":" 88 | #define SEP_VERSION_STR STRINGIFY(SEP_MAJOR_VERSION) "." STRINGIFY(SEP_MINOR_VERSION) 89 | 90 | #if defined(DRV_OS_WINDOWS) 91 | 92 | #define SEP_DRIVER_NAME SEP_NAME "drv" STRINGIFY(SEP_MAJOR_VERSION) 93 | #define SEP_DRIVER_NAME_W SEP_NAME_W L"drv" STRINGIFY_W(SEP_MAJOR_VERSION) 94 | #define SEP_DEVICE_NAME SEP_DRIVER_NAME 95 | 96 | #define SEP_PREV_DRIVER_NAME SEP_NAME "drv" STRINGIFY(SEP_PREV_MAJOR_VERSION) 97 | #define SEP_PREV_DRIVER_NAME_W SEP_NAME_W L"drv" STRINGIFY_W(SEP_PREV_MAJOR_VERSION) 98 | #define SEP_PREV_DEVICE_NAME SEP_PREV_DRIVER_NAME 99 | 100 | #endif 101 | 102 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 103 | 104 | #define SEP_DRIVER_NAME SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) 105 | #define SEP_SAMPLES_NAME SEP_DRIVER_NAME "_s" 106 | #define SEP_UNCORE_NAME SEP_DRIVER_NAME "_u" 107 | #define SEP_SIDEBAND_NAME SEP_DRIVER_NAME "_b" 108 | #define SEP_EMON_NAME SEP_DRIVER_NAME "_e" 109 | #define SEP_DEVICE_NAME "/dev/" SEP_DRIVER_NAME 110 | 111 | #define SEP_PREV_DRIVER_NAME SEP_NAME STRINGIFY(SEP_PREV_MAJOR_VERSION) 112 | #define SEP_PREV_SAMPLES_NAME SEP_PREV_DRIVER_NAME "_s" 113 | #define SEP_PREV_UNCORE_NAME SEP_PREV_DRIVER_NAME "_u" 114 | #define SEP_PREV_SIDEBAND_NAME SEP_PREV_DRIVER_NAME "_b" 115 | #define SEP_PREV_DEVICE_NAME "/dev/" SEP_PREV_DRIVER_NAME 116 | 117 | #endif 118 | 119 | #if defined(DRV_OS_MAC) 120 | 121 | #define SEP_DRIVER_NAME SEP_NAME STRINGIFY(SEP_MAJOR_VERSION) 122 | #define SEP_SAMPLES_NAME SEP_DRIVER_NAME "_s" 123 | #define SEP_DEVICE_NAME SEP_DRIVER_NAME 124 | 125 | #define SEP_PREV_DRIVER_NAME SEP_NAME STRINGIFY(SEP_PREV_MAJOR_VERSION) 126 | #define SEP_PREV_SAMPLES_NAME SEP_PREV_DRIVER_NAME "_s" 127 | #define SEP_PREV_DEVICE_NAME SEP_PREV_DRIVER_NAME 128 | 129 | #endif 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /sepdk/src/inc/asm_helper.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _ASM_HELPER_H_ 34 | #define _ASM_HELPER_H_ 35 | 36 | #include 37 | 38 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,1,0) 39 | 40 | #include 41 | #include 42 | 43 | #else 44 | 45 | #ifdef CONFIG_AS_CFI 46 | 47 | #define CFI_STARTPROC .cfi_startproc 48 | #define CFI_ENDPROC .cfi_endproc 49 | #define CFI_ADJUST_CFA_OFFSET .cfi_adjust_cfa_offset 50 | #define CFI_REL_OFFSET .cfi_rel_offset 51 | #define CFI_RESTORE .cfi_restore 52 | 53 | #else 54 | 55 | .macro cfi_ignore a=0, b=0, c=0, d=0 56 | .endm 57 | 58 | #define CFI_STARTPROC cfi_ignore 59 | #define CFI_ENDPROC cfi_ignore 60 | #define CFI_ADJUST_CFA_OFFSET cfi_ignore 61 | #define CFI_REL_OFFSET cfi_ignore 62 | #define CFI_RESTORE cfi_ignore 63 | #endif 64 | 65 | #ifdef CONFIG_X86_64 66 | .macro SAVE_C_REGS_HELPER offset=0 rax=1 rcx=1 r8910=1 r11=1 67 | .if \r11 68 | movq %r11, 6*8+\offset(%rsp) 69 | CFI_REL_OFFSET r11, \offset 70 | .endif 71 | .if \r8910 72 | movq %r10, 7*8+\offset(%rsp) 73 | CFI_REL_OFFSET r10, \offset 74 | movq %r9, 8*8+\offset(%rsp) 75 | CFI_REL_OFFSET r9, \offset 76 | movq %r8, 9*8+\offset(%rsp) 77 | CFI_REL_OFFSET r8, \offset 78 | .endif 79 | .if \rax 80 | movq %rax, 10*8+\offset(%rsp) 81 | CFI_REL_OFFSET rax, \offset 82 | .endif 83 | .if \rcx 84 | movq %rcx, 11*8+\offset(%rsp) 85 | CFI_REL_OFFSET rcx, \offset 86 | .endif 87 | movq %rdx, 12*8+\offset(%rsp) 88 | CFI_REL_OFFSET rdx, \offset 89 | movq %rsi, 13*8+\offset(%rsp) 90 | CFI_REL_OFFSET rsi, \offset 91 | movq %rdi, 14*8+\offset(%rsp) 92 | CFI_REL_OFFSET rdi, \offset 93 | .endm 94 | .macro SAVE_C_REGS offset=0 95 | SAVE_C_REGS_HELPER \offset, 1, 1, 1, 1 96 | .endm 97 | .macro SAVE_EXTRA_REGS offset=0 98 | movq %r15, 0*8+\offset(%rsp) 99 | CFI_REL_OFFSET r15, \offset 100 | movq %r14, 1*8+\offset(%rsp) 101 | CFI_REL_OFFSET r14, \offset 102 | movq %r13, 2*8+\offset(%rsp) 103 | CFI_REL_OFFSET r13, \offset 104 | movq %r12, 3*8+\offset(%rsp) 105 | CFI_REL_OFFSET r12, \offset 106 | movq %rbp, 4*8+\offset(%rsp) 107 | CFI_REL_OFFSET rbp, \offset 108 | movq %rbx, 5*8+\offset(%rsp) 109 | CFI_REL_OFFSET rbx, \offset 110 | .endm 111 | 112 | .macro RESTORE_EXTRA_REGS offset=0 113 | movq 0*8+\offset(%rsp), %r15 114 | CFI_RESTORE r15 115 | movq 1*8+\offset(%rsp), %r14 116 | CFI_RESTORE r14 117 | movq 2*8+\offset(%rsp), %r13 118 | CFI_RESTORE r13 119 | movq 3*8+\offset(%rsp), %r12 120 | CFI_RESTORE r12 121 | movq 4*8+\offset(%rsp), %rbp 122 | CFI_RESTORE rbp 123 | movq 5*8+\offset(%rsp), %rbx 124 | CFI_RESTORE rbx 125 | .endm 126 | .macro RESTORE_C_REGS_HELPER rstor_rax=1, rstor_rcx=1, rstor_r11=1, rstor_r8910=1, rstor_rdx=1 127 | .if \rstor_r11 128 | movq 6*8(%rsp), %r11 129 | CFI_RESTORE r11 130 | .endif 131 | .if \rstor_r8910 132 | movq 7*8(%rsp), %r10 133 | CFI_RESTORE r10 134 | movq 8*8(%rsp), %r9 135 | CFI_RESTORE r9 136 | movq 9*8(%rsp), %r8 137 | CFI_RESTORE r8 138 | .endif 139 | .if \rstor_rax 140 | movq 10*8(%rsp), %rax 141 | CFI_RESTORE rax 142 | .endif 143 | .if \rstor_rcx 144 | movq 11*8(%rsp), %rcx 145 | CFI_RESTORE rcx 146 | .endif 147 | .if \rstor_rdx 148 | movq 12*8(%rsp), %rdx 149 | CFI_RESTORE rdx 150 | .endif 151 | movq 13*8(%rsp), %rsi 152 | CFI_RESTORE rsi 153 | movq 14*8(%rsp), %rdi 154 | CFI_RESTORE rdi 155 | .endm 156 | .macro RESTORE_C_REGS 157 | RESTORE_C_REGS_HELPER 1,1,1,1,1 158 | .endm 159 | 160 | .macro ALLOC_PT_GPREGS_ON_STACK addskip=0 161 | subq $15*8+\addskip, %rsp 162 | CFI_ADJUST_CFA_OFFSET 15*8+\addskip 163 | .endm 164 | 165 | .macro REMOVE_PT_GPREGS_FROM_STACK addskip=0 166 | addq $15*8+\addskip, %rsp 167 | CFI_ADJUST_CFA_OFFSET -(15*8+\addskip) 168 | .endm 169 | 170 | .macro SAVE_ALL 171 | ALLOC_PT_GPREGS_ON_STACK 172 | SAVE_C_REGS 173 | SAVE_EXTRA_REGS 174 | .endm 175 | 176 | .macro RESTORE_ALL 177 | RESTORE_EXTRA_REGS 178 | RESTORE_C_REGS 179 | REMOVE_PT_GPREGS_FROM_STACK 180 | .endm 181 | #endif //CONFIG_X86_64 182 | #endif 183 | 184 | #endif 185 | 186 | -------------------------------------------------------------------------------- /tests/apps/target/test.c: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define MAX_NUM_THREADS 1024 37 | #define MIN_DATA_SIZE 0x4000 38 | #define MAX_DATA_SIZE 0x400000 39 | #define DEF_DATA_SIZE 0x10000 40 | #define ONE_TIME_EXECUTION 0 41 | #define INFINITE_EXECUTION 1 42 | 43 | static char usage[] = "USAGE: test -nt 8 [-s Byte]"; 44 | pthread_t trids[MAX_NUM_THREADS]; 45 | long dataSize = DEF_DATA_SIZE; 46 | long primeNum[MAX_NUM_THREADS]; 47 | long *src_buffer; 48 | unsigned int numberOfThread = 0; 49 | unsigned int thread[MAX_NUM_THREADS]; 50 | 51 | bool isPrime(unsigned int n) 52 | { 53 | if (n <= 1) return false; 54 | 55 | for (unsigned int i = 2; i <= n / 2; i++) 56 | { 57 | if (n % i == 0) return false; 58 | } 59 | 60 | return true; 61 | } 62 | 63 | void generatePrimeNum(long *primeNumArray, unsigned int primeNumArrayLength) 64 | { 65 | if(!primeNumArray) return; 66 | 67 | unsigned int indexNaturalNum = 0; 68 | for(unsigned int j = 0; j < primeNumArrayLength; j++) 69 | { 70 | while(!isPrime(++indexNaturalNum)) 71 | { 72 | if(indexNaturalNum == UINT32_MAX) break; 73 | } 74 | 75 | if(indexNaturalNum != UINT32_MAX) 76 | { 77 | primeNumArray[j] = indexNaturalNum; 78 | } 79 | } 80 | } 81 | 82 | void allocateMemory() 83 | { 84 | src_buffer = (long*)malloc(sizeof(long) * dataSize); 85 | if (!src_buffer) 86 | { 87 | printf("Error allocating memory\n"); 88 | printf("Try key: -s [Bytes]. DEF_DATA_SIZE = 0x%x bytes\n", DEF_DATA_SIZE); 89 | exit(1); 90 | } 91 | } 92 | 93 | void argParse(int argc, char** argv) 94 | { 95 | if (argc >= 3 && strcmp((argv[1]),"-nt") == 0) 96 | { 97 | numberOfThread = atoi(argv[2]); 98 | if (argc == 5 && strcmp((argv[3]),"-s") == 0) 99 | { 100 | dataSize = atol(argv[4]); 101 | } 102 | if(numberOfThread > 0 && numberOfThread <= MAX_NUM_THREADS && dataSize >= MIN_DATA_SIZE && dataSize <= MAX_DATA_SIZE) 103 | { 104 | printf("nt = %d\n", numberOfThread); 105 | printf("dataSize = 0x%lx\n", dataSize); 106 | return; 107 | } 108 | } 109 | printf("%s\n",usage); 110 | printf("Max threads: %d\n", MAX_NUM_THREADS); 111 | printf("Min data size: 0x%x\n", MIN_DATA_SIZE); 112 | printf("Max data size: 0x%x\n", MAX_DATA_SIZE); 113 | exit(1); 114 | } 115 | 116 | size_t load(long step, long count, int flag) 117 | { 118 | size_t ip; 119 | do 120 | { 121 | asm ( 122 | "lea 0x3(%%rip), %%rdx;" 123 | "label:" 124 | "movq (%[msbuf]), %%rsi;" 125 | "movq %%rsi, (%[msbuf]);" 126 | "leaq (%[msbuf], %[mp], 8), %[msbuf];" 127 | "loop label;" 128 | :"=d"(ip) 129 | :[msbuf] "a" (src_buffer), [mp] "b" (step), [mds] "c" (count) 130 | ); 131 | } while(flag); 132 | return ip; 133 | } 134 | 135 | void* worker(void* threadNumArg) 136 | { 137 | unsigned int threadNum = *(unsigned int*)(threadNumArg); 138 | long step = primeNum[threadNum]; 139 | long count = dataSize / step; 140 | load(step, count, INFINITE_EXECUTION); 141 | return NULL; 142 | } 143 | 144 | void printHotspotIP() 145 | { 146 | long step = 0; 147 | long count = 1; 148 | size_t ip = load(step, count, ONE_TIME_EXECUTION); 149 | printf("Hotspot ip: %lX : %ld\n", ip, ip); 150 | } 151 | 152 | void createWorkers() 153 | { 154 | printf("numberOfThreads = %d\n", numberOfThread); 155 | 156 | for(unsigned int threadNum = 0; threadNum < numberOfThread; threadNum++) 157 | { 158 | thread[threadNum] = threadNum; 159 | pthread_create(&trids[threadNum], NULL, worker, &thread[threadNum]); 160 | } 161 | } 162 | 163 | void waitForWorkers() 164 | { 165 | for(unsigned int threadNum = 0; threadNum < numberOfThread; threadNum++) 166 | { 167 | pthread_join(trids[threadNum], NULL); 168 | if (src_buffer) free(src_buffer); 169 | } 170 | } 171 | 172 | int main(int argc, char** argv) 173 | { 174 | argParse(argc, argv); 175 | 176 | generatePrimeNum(primeNum, MAX_NUM_THREADS); 177 | 178 | allocateMemory(); 179 | printHotspotIP(); 180 | 181 | createWorkers(); 182 | waitForWorkers(); 183 | 184 | return 0; 185 | } 186 | -------------------------------------------------------------------------------- /sepdk/include/lwpmudrv_types.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _LWPMUDRV_TYPES_H_ 30 | #define _LWPMUDRV_TYPES_H_ 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | #if defined(BUILD_DRV_ESX) 37 | //SR: added size_t def 38 | typedef unsigned long size_t; 39 | typedef unsigned long ssize_t; 40 | #endif 41 | 42 | typedef unsigned char U8; 43 | typedef char S8; 44 | typedef short S16; 45 | typedef unsigned short U16; 46 | typedef unsigned int U32; 47 | typedef int S32; 48 | #if defined(DRV_OS_WINDOWS) 49 | typedef unsigned __int64 U64; 50 | typedef __int64 S64; 51 | #elif defined (DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_MAC) || defined (DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 52 | typedef unsigned long long U64; 53 | typedef long long S64; 54 | typedef unsigned long ULONG; 55 | typedef void VOID; 56 | typedef void* LPVOID; 57 | 58 | #if defined(BUILD_DRV_ESX) 59 | //SR: added UWORD64 def 60 | typedef union _UWORD64 { 61 | struct { 62 | U32 low; 63 | S32 hi; 64 | } c; 65 | S64 qword; 66 | } UWORD64, *PWORD64; 67 | #endif 68 | #else 69 | #error "Undefined OS" 70 | #endif 71 | 72 | #if defined(DRV_IA32) 73 | typedef S32 SIOP; 74 | typedef U32 UIOP; 75 | #elif defined(DRV_EM64T) 76 | typedef S64 SIOP; 77 | typedef U64 UIOP; 78 | #else 79 | #error "Unexpected Architecture seen" 80 | #endif 81 | 82 | typedef U32 DRV_BOOL; 83 | typedef void* PVOID; 84 | 85 | #if !defined(__DEFINE_STCHAR__) 86 | #define __DEFINE_STCHAR__ 87 | #if defined(UNICODE) 88 | typedef wchar_t STCHAR; 89 | #define VTSA_T(x) L ## x 90 | #else 91 | typedef char STCHAR; 92 | #define VTSA_T(x) x 93 | #endif 94 | #endif 95 | 96 | #if defined(DRV_OS_WINDOWS) 97 | #include 98 | typedef wchar_t DRV_STCHAR; 99 | typedef wchar_t VTSA_CHAR; 100 | #else 101 | typedef char DRV_STCHAR; 102 | #endif 103 | 104 | // 105 | // Handy Defines 106 | // 107 | typedef U32 DRV_STATUS; 108 | 109 | #define MAX_STRING_LENGTH 1024 110 | #define MAXNAMELEN 256 111 | #define MAX_PATH_BUFFER_LENGTH 1100 112 | #define MAX_PATH_USER_LENGTH 1024 113 | 114 | #if defined (DRV_OS_WINDOWS) 115 | #define WIN_MAX_RELATIVE_PATH_LENGTH 200 116 | #define WIN_VOLUME_LABEL_INDICATOR L":\\" 117 | #define WIN_PATH_LENGTH_EXTEND_PREFIX L"\\\\?\\" 118 | #endif 119 | 120 | #if defined(DRV_OS_WINDOWS) 121 | #define UNLINK _unlink 122 | #define RENAME rename 123 | #define WCSDUP _wcsdup 124 | #endif 125 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_MAC) || defined (DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 126 | #define UNLINK unlink 127 | #define RENAME rename 128 | #endif 129 | 130 | #if defined(DRV_OS_SOLARIS) && !defined(_KERNEL) 131 | //wcsdup is missing on Solaris 132 | #include 133 | #include 134 | 135 | static inline wchar_t* solaris_wcsdup(const wchar_t *wc) 136 | { 137 | wchar_t *tmp = (wchar_t *)malloc((wcslen(wc) + 1) * sizeof(wchar_t)); 138 | wcscpy(tmp, wc); 139 | return tmp; 140 | } 141 | #define WCSDUP solaris_wcsdup 142 | #endif 143 | 144 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_FREEBSD) || defined(DRV_OS_MAC) 145 | #define WCSDUP wcsdup 146 | #endif 147 | 148 | #if !defined(_WCHAR_T_DEFINED) 149 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_ANDROID) || defined(DRV_OS_SOLARIS) 150 | #if !defined(_GNU_SOURCE) 151 | #define _GNU_SOURCE 152 | #endif 153 | #endif 154 | #endif 155 | 156 | #if (defined(DRV_OS_LINUX) || defined(DRV_OS_ANDROID)) && !defined(__KERNEL__) 157 | #include 158 | typedef wchar_t VTSA_CHAR; 159 | #endif 160 | 161 | #if (defined(DRV_OS_MAC) || defined(DRV_OS_FREEBSD) || defined(DRV_OS_SOLARIS)) && !defined(_KERNEL) 162 | #include 163 | typedef wchar_t VTSA_CHAR; 164 | #endif 165 | 166 | 167 | #define TRUE 1 168 | #define FALSE 0 169 | 170 | #define ALIGN_4(x) (((x) + 3) & ~3) 171 | #define ALIGN_8(x) (((x) + 7) & ~7) 172 | #define ALIGN_16(x) (((x) + 15) & ~15) 173 | #define ALIGN_32(x) (((x) + 31) & ~31) 174 | 175 | #if defined(__cplusplus) 176 | } 177 | #endif 178 | 179 | #endif 180 | 181 | -------------------------------------------------------------------------------- /agentdk/include/lwpmudrv_types.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _LWPMUDRV_TYPES_H_ 30 | #define _LWPMUDRV_TYPES_H_ 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | #if defined(BUILD_DRV_ESX) 37 | //SR: added size_t def 38 | typedef unsigned long size_t; 39 | typedef unsigned long ssize_t; 40 | #endif 41 | 42 | typedef unsigned char U8; 43 | typedef char S8; 44 | typedef short S16; 45 | typedef unsigned short U16; 46 | typedef unsigned int U32; 47 | typedef int S32; 48 | #if defined(DRV_OS_WINDOWS) 49 | typedef unsigned __int64 U64; 50 | typedef __int64 S64; 51 | #elif defined (DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_MAC) || defined (DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 52 | typedef unsigned long long U64; 53 | typedef long long S64; 54 | typedef unsigned long ULONG; 55 | typedef void VOID; 56 | typedef void* LPVOID; 57 | 58 | #if defined(BUILD_DRV_ESX) 59 | //SR: added UWORD64 def 60 | typedef union _UWORD64 { 61 | struct { 62 | U32 low; 63 | S32 hi; 64 | } c; 65 | S64 qword; 66 | } UWORD64, *PWORD64; 67 | #endif 68 | #else 69 | #error "Undefined OS" 70 | #endif 71 | 72 | #if defined(DRV_IA32) 73 | typedef S32 SIOP; 74 | typedef U32 UIOP; 75 | #elif defined(DRV_EM64T) 76 | typedef S64 SIOP; 77 | typedef U64 UIOP; 78 | #else 79 | #error "Unexpected Architecture seen" 80 | #endif 81 | 82 | typedef U32 DRV_BOOL; 83 | typedef void* PVOID; 84 | 85 | #if !defined(__DEFINE_STCHAR__) 86 | #define __DEFINE_STCHAR__ 87 | #if defined(UNICODE) 88 | typedef wchar_t STCHAR; 89 | #define VTSA_T(x) L ## x 90 | #else 91 | typedef char STCHAR; 92 | #define VTSA_T(x) x 93 | #endif 94 | #endif 95 | 96 | #if defined(DRV_OS_WINDOWS) 97 | #include 98 | typedef wchar_t DRV_STCHAR; 99 | typedef wchar_t VTSA_CHAR; 100 | #else 101 | typedef char DRV_STCHAR; 102 | #endif 103 | 104 | // 105 | // Handy Defines 106 | // 107 | typedef U32 DRV_STATUS; 108 | 109 | #define MAX_STRING_LENGTH 1024 110 | #define MAXNAMELEN 256 111 | #define MAX_PATH_BUFFER_LENGTH 1100 112 | #define MAX_PATH_USER_LENGTH 1024 113 | 114 | #if defined (DRV_OS_WINDOWS) 115 | #define WIN_MAX_RELATIVE_PATH_LENGTH 200 116 | #define WIN_VOLUME_LABEL_INDICATOR L":\\" 117 | #define WIN_PATH_LENGTH_EXTEND_PREFIX L"\\\\?\\" 118 | #endif 119 | 120 | #if defined(DRV_OS_WINDOWS) 121 | #define UNLINK _unlink 122 | #define RENAME rename 123 | #define WCSDUP _wcsdup 124 | #endif 125 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_MAC) || defined (DRV_OS_ANDROID) || defined(DRV_OS_FREEBSD) 126 | #define UNLINK unlink 127 | #define RENAME rename 128 | #endif 129 | 130 | #if defined(DRV_OS_SOLARIS) && !defined(_KERNEL) 131 | //wcsdup is missing on Solaris 132 | #include 133 | #include 134 | 135 | static inline wchar_t* solaris_wcsdup(const wchar_t *wc) 136 | { 137 | wchar_t *tmp = (wchar_t *)malloc((wcslen(wc) + 1) * sizeof(wchar_t)); 138 | wcscpy(tmp, wc); 139 | return tmp; 140 | } 141 | #define WCSDUP solaris_wcsdup 142 | #endif 143 | 144 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_FREEBSD) || defined(DRV_OS_MAC) 145 | #define WCSDUP wcsdup 146 | #endif 147 | 148 | #if !defined(_WCHAR_T_DEFINED) 149 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_ANDROID) || defined(DRV_OS_SOLARIS) 150 | #if !defined(_GNU_SOURCE) 151 | #define _GNU_SOURCE 152 | #endif 153 | #endif 154 | #endif 155 | 156 | #if (defined(DRV_OS_LINUX) || defined(DRV_OS_ANDROID)) && !defined(__KERNEL__) 157 | #include 158 | typedef wchar_t VTSA_CHAR; 159 | #endif 160 | 161 | #if (defined(DRV_OS_MAC) || defined(DRV_OS_FREEBSD) || defined(DRV_OS_SOLARIS)) && !defined(_KERNEL) 162 | #include 163 | typedef wchar_t VTSA_CHAR; 164 | #endif 165 | 166 | 167 | #define TRUE 1 168 | #define FALSE 0 169 | 170 | #define ALIGN_4(x) (((x) + 3) & ~3) 171 | #define ALIGN_8(x) (((x) + 7) & ~7) 172 | #define ALIGN_16(x) (((x) + 15) & ~15) 173 | #define ALIGN_32(x) (((x) + 31) & ~31) 174 | 175 | #if defined(__cplusplus) 176 | } 177 | #endif 178 | 179 | #endif 180 | 181 | -------------------------------------------------------------------------------- /sepdk/src/apic.c: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2005-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | 34 | #include "lwpmudrv_defines.h" 35 | #include 36 | #include 37 | #include 38 | #include 39 | #if defined(CONFIG_XEN) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32) 40 | #include 41 | #endif 42 | #if defined(CONFIG_XEN_DOM0) && LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0) 43 | #include 44 | #include 45 | #endif 46 | 47 | #include "lwpmudrv_types.h" 48 | #include "rise_errors.h" 49 | #include "lwpmudrv_ecb.h" 50 | #include "apic.h" 51 | #include "lwpmudrv.h" 52 | #include "control.h" 53 | #include "utility.h" 54 | 55 | static DEFINE_PER_CPU(unsigned long, saved_apic_lvtpc); 56 | 57 | 58 | 59 | /*! 60 | * @fn VOID apic_Get_APIC_ID(S32 cpu) 61 | * 62 | * @brief Obtain APIC ID 63 | * 64 | * @param S32 cpuid - cpu index 65 | * 66 | * @return U32 APIC ID 67 | */ 68 | VOID 69 | apic_Get_APIC_ID(S32 cpu) 70 | { 71 | U32 apic_id = 0; 72 | CPU_STATE pcpu; 73 | 74 | SEP_DRV_LOG_TRACE_IN("CPU: %d.", cpu); 75 | pcpu = &pcb[cpu]; 76 | 77 | #if defined(CONFIG_XEN_DOM0) && LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0) 78 | if (xen_initial_domain()) { 79 | S32 ret = 0; 80 | struct xen_platform_op op = { 81 | .cmd = XENPF_get_cpuinfo, 82 | .interface_version = XENPF_INTERFACE_VERSION, 83 | .u.pcpu_info.xen_cpuid = cpu, 84 | }; 85 | 86 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0) 87 | ret = HYPERVISOR_platform_op(&op); 88 | #else 89 | ret = HYPERVISOR_dom0_op(&op); 90 | #endif 91 | if (ret) { 92 | SEP_DRV_LOG_ERROR("apic_Get_APIC_ID: Error in reading APIC ID on Xen PV."); 93 | apic_id = 0; 94 | } else { 95 | apic_id = op.u.pcpu_info.apic_id; 96 | } 97 | } else { 98 | #endif 99 | apic_id = read_apic_id(); 100 | #if defined(CONFIG_XEN_DOM0) && LINUX_VERSION_CODE > KERNEL_VERSION(3,3,0) 101 | } 102 | #endif 103 | 104 | CPU_STATE_apic_id(pcpu) = apic_id; 105 | 106 | SEP_DRV_LOG_TRACE_OUT("Apic_id[%d] is %d.", cpu, CPU_STATE_apic_id(pcpu)); 107 | } 108 | 109 | 110 | /*! 111 | * @fn extern VOID APIC_Init(param) 112 | * 113 | * @brief initialize the local APIC 114 | * 115 | * @param int cpu_idx - The cpu to deinit 116 | * 117 | * @return None 118 | * 119 | * Special Notes: 120 | * This routine is expected to be called via the CONTROL_Parallel routine 121 | */ 122 | extern VOID 123 | APIC_Init (PVOID param) 124 | { 125 | int me; 126 | 127 | SEP_DRV_LOG_TRACE_IN("Param: %p.", param); 128 | 129 | preempt_disable(); 130 | me = CONTROL_THIS_CPU(); 131 | preempt_enable(); 132 | 133 | apic_Get_APIC_ID(me); 134 | 135 | SEP_DRV_LOG_TRACE_OUT(""); 136 | } 137 | 138 | /*! 139 | * @fn extern VOID APIC_Install_Interrupt_Handler(param) 140 | * 141 | * @brief Install the interrupt handler 142 | * 143 | * @param int param - The linear address of the Local APIC 144 | * 145 | * @return None 146 | * 147 | * Special Notes: 148 | * The linear address is necessary if the LAPIC is used. If X2APIC is 149 | * used the linear address is not necessary. 150 | */ 151 | extern VOID 152 | APIC_Install_Interrupt_Handler (PVOID param) 153 | { 154 | SEP_DRV_LOG_TRACE_IN("Param: %p.", param); 155 | 156 | per_cpu(saved_apic_lvtpc, CONTROL_THIS_CPU()) = apic_read(APIC_LVTPC); 157 | apic_write(APIC_LVTPC, APIC_DM_NMI); 158 | 159 | SEP_DRV_LOG_TRACE_OUT(""); 160 | } 161 | 162 | 163 | /*! 164 | * @fn extern VOID APIC_Enable_PMI(void) 165 | * 166 | * @brief Enable the PMU interrupt 167 | * 168 | * @param None 169 | * 170 | * @return None 171 | * 172 | * Special Notes: 173 | * 174 | */ 175 | extern VOID 176 | APIC_Enable_Pmi(VOID) 177 | { 178 | SEP_DRV_LOG_TRACE_IN(""); 179 | 180 | apic_write(APIC_LVTPC, APIC_DM_NMI); 181 | 182 | SEP_DRV_LOG_TRACE_OUT(""); 183 | } 184 | 185 | 186 | /*! 187 | * @fn extern VOID APIC_Restore_LVTPC(void) 188 | * 189 | * @brief Restore APIC LVTPC value 190 | * 191 | * @param None 192 | * 193 | * @return None 194 | * 195 | * Special Notes: 196 | * 197 | */ 198 | extern VOID 199 | APIC_Restore_LVTPC(PVOID param) 200 | { 201 | SEP_DRV_LOG_TRACE_IN(""); 202 | 203 | apic_write(APIC_LVTPC, per_cpu(saved_apic_lvtpc, CONTROL_THIS_CPU())); 204 | 205 | SEP_DRV_LOG_TRACE_OUT(""); 206 | } 207 | 208 | -------------------------------------------------------------------------------- /sepdk/src/unc_sa.c: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2011-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #include "lwpmudrv_defines.h" 34 | #include "lwpmudrv_types.h" 35 | #include "lwpmudrv_ecb.h" 36 | #include "lwpmudrv_struct.h" 37 | 38 | #include "inc/ecb_iterators.h" 39 | #include "inc/control.h" 40 | #include "inc/haswellunc_sa.h" 41 | #include "inc/pci.h" 42 | #include "inc/utility.h" 43 | 44 | extern U64 *read_counter_info; 45 | extern DRV_CONFIG drv_cfg; 46 | 47 | #if !defined(DISABLE_BUILD_SOCPERF) 48 | extern VOID SOCPERF_Read_Data3(PVOID data_buffer); 49 | #endif 50 | 51 | 52 | 53 | /*! 54 | * @fn static VOID hswunc_sa_Initialize(PVOID) 55 | * 56 | * @brief Initialize any registers or addresses 57 | * 58 | * @param param 59 | * 60 | * @return None 61 | * 62 | * Special Notes: 63 | */ 64 | static VOID 65 | hswunc_sa_Initialize ( 66 | VOID *param 67 | ) 68 | { 69 | SEP_DRV_LOG_TRACE_IN("Param: %p.", param); 70 | SEP_DRV_LOG_TRACE_OUT("Empty function."); 71 | return; 72 | } 73 | 74 | 75 | /* ------------------------------------------------------------------------- */ 76 | /*! 77 | * @fn hswunc_sa_Read_Counts(param, id, read_from_intr) 78 | * 79 | * @param param Pointer to populate read data 80 | * @param id Device index 81 | * @param read_from_intr Read data from interrupt or timer 82 | * 83 | * @return None No return needed 84 | * 85 | * @brief Read the Uncore count data and store into the buffer param; 86 | * 87 | */ 88 | static VOID 89 | hswunc_sa_Trigger_Read ( 90 | PVOID param, 91 | U32 id, 92 | U32 read_from_intr 93 | ) 94 | { 95 | U64 *data = (U64*) param; 96 | U32 cur_grp; 97 | ECB pecb; 98 | U32 this_cpu; 99 | U32 package_num; 100 | 101 | SEP_DRV_LOG_TRACE_IN("Param: %p, id: %u.", param, id); 102 | 103 | this_cpu = CONTROL_THIS_CPU(); 104 | package_num = core_to_package_map[this_cpu]; 105 | cur_grp = LWPMU_DEVICE_cur_group(&devices[id])[package_num]; 106 | pecb = LWPMU_DEVICE_PMU_register_data(&devices[id])[cur_grp]; 107 | 108 | // group id 109 | data = (U64*)((S8*)data + ECB_group_offset(pecb)); 110 | #if !defined(DISABLE_BUILD_SOCPERF) 111 | SOCPERF_Read_Data3((void*)data); 112 | #endif 113 | 114 | SEP_DRV_LOG_TRACE_OUT(""); 115 | return; 116 | } 117 | 118 | 119 | /* ------------------------------------------------------------------------- */ 120 | /*! 121 | * @fn hswunc_sa_Read_PMU_Data(param) 122 | * 123 | * @param param the device index 124 | * 125 | * @return None No return needed 126 | * 127 | * @brief Read the Uncore count data and store into the buffer param; 128 | * 129 | */ 130 | static VOID 131 | hswunc_sa_Read_PMU_Data ( 132 | PVOID param, 133 | U32 dev_idx 134 | ) 135 | { 136 | U32 j; 137 | U64 *buffer = (U64 *)param; 138 | U32 this_cpu; 139 | CPU_STATE pcpu; 140 | U32 event_index = 0; 141 | U64 counter_buffer[HSWUNC_SA_MAX_COUNTERS+1]; 142 | 143 | SEP_DRV_LOG_TRACE_IN("Param: %p.", param); 144 | 145 | this_cpu = CONTROL_THIS_CPU(); 146 | pcpu = &pcb[this_cpu]; 147 | 148 | // NOTE THAT the read_pmu function on for EMON collection. 149 | if (!DRV_CONFIG_emon_mode(drv_cfg)) { 150 | SEP_DRV_LOG_TRACE_OUT("Early exit (!emon_mode)."); 151 | return; 152 | } 153 | if (!CPU_STATE_system_master(pcpu)) { 154 | SEP_DRV_LOG_TRACE_OUT("Early exit (!system_master)."); 155 | return; 156 | } 157 | 158 | #if !defined(DISABLE_BUILD_SOCPERF) 159 | SOCPERF_Read_Data3((void*)counter_buffer); 160 | #endif 161 | 162 | FOR_EACH_PCI_DATA_REG_RAW(pecb, i, dev_idx) { 163 | j = ECB_entries_uncore_buffer_offset_in_system(pecb,i); 164 | buffer[j] = counter_buffer[event_index+1]; 165 | event_index++; 166 | SEP_DRV_LOG_TRACE("j=%u, value=%llu, cpu=%u", j, buffer[j], this_cpu); 167 | 168 | } END_FOR_EACH_PCI_DATA_REG_RAW; 169 | 170 | SEP_DRV_LOG_TRACE_OUT(""); 171 | return; 172 | } 173 | 174 | 175 | /* 176 | * Initialize the dispatch table 177 | */ 178 | DISPATCH_NODE hswunc_sa_dispatch = 179 | { 180 | hswunc_sa_Initialize, // initialize 181 | NULL, // destroy 182 | NULL, // write 183 | NULL, // freeze 184 | NULL, // restart 185 | hswunc_sa_Read_PMU_Data, // read 186 | NULL, // check for overflow 187 | NULL, // swap group 188 | NULL, // read lbrs 189 | NULL, // cleanup 190 | NULL, // hw errata 191 | NULL, // read power 192 | NULL, // check overflow errata 193 | NULL, // read counts 194 | NULL, // check overflow gp errata 195 | NULL, // read_ro 196 | NULL, // platform info 197 | hswunc_sa_Trigger_Read, // trigger read 198 | NULL, // scan for uncore 199 | NULL // read metrics 200 | }; 201 | 202 | -------------------------------------------------------------------------------- /sepdk/src/inc/pci.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2012-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _PCI_H_ 34 | #define _PCI_H_ 35 | 36 | #include "lwpmudrv_defines.h" 37 | 38 | /* 39 | * PCI Config Address macros 40 | */ 41 | #define PCI_ENABLE 0x80000000 42 | 43 | #define PCI_ADDR_IO 0xCF8 44 | #define PCI_DATA_IO 0xCFC 45 | 46 | #define BIT0 0x1 47 | #define BIT1 0x2 48 | 49 | /* 50 | * Macro for forming a PCI configuration address 51 | */ 52 | #define FORM_PCI_ADDR(bus,dev,fun,off) (((PCI_ENABLE)) | \ 53 | ((bus & 0xFF) << 16) | \ 54 | ((dev & 0x1F) << 11) | \ 55 | ((fun & 0x07) << 8) | \ 56 | ((off & 0xFF) << 0)) 57 | 58 | #define VENDOR_ID_MASK 0x0000FFFF 59 | #define DEVICE_ID_MASK 0xFFFF0000 60 | #define DEVICE_ID_BITSHIFT 16 61 | #define LOWER_4_BYTES_MASK 0x00000000FFFFFFFF 62 | #define MAX_BUSNO 256 63 | #define NEXT_ADDR_OFFSET 4 64 | #define NEXT_ADDR_SHIFT 32 65 | #define DRV_IS_PCI_VENDOR_ID_INTEL 0x8086 66 | #define MAX_PCI_DEVS 32 67 | 68 | #define CONTINUE_IF_NOT_GENUINE_INTEL_DEVICE(value, vendor_id, device_id) \ 69 | { \ 70 | vendor_id = value & VENDOR_ID_MASK; \ 71 | device_id = (value & DEVICE_ID_MASK) >> DEVICE_ID_BITSHIFT; \ 72 | \ 73 | if (vendor_id != DRV_IS_PCI_VENDOR_ID_INTEL) { \ 74 | continue; \ 75 | } \ 76 | \ 77 | } 78 | 79 | #define CHECK_IF_GENUINE_INTEL_DEVICE(value, vendor_id, device_id, valid) \ 80 | { \ 81 | vendor_id = value & VENDOR_ID_MASK; \ 82 | device_id = (value & DEVICE_ID_MASK) >> DEVICE_ID_BITSHIFT; \ 83 | \ 84 | valid = 1; \ 85 | if (vendor_id != DRV_IS_PCI_VENDOR_ID_INTEL) { \ 86 | valid = 0; \ 87 | } \ 88 | \ 89 | } 90 | 91 | 92 | typedef struct SEP_MMIO_NODE_S SEP_MMIO_NODE; 93 | 94 | struct SEP_MMIO_NODE_S { 95 | U64 physical_address; 96 | U64 virtual_address; 97 | U64 map_token; 98 | U32 size; 99 | }; 100 | 101 | #define SEP_MMIO_NODE_physical_address(x) ((x)->physical_address) 102 | #define SEP_MMIO_NODE_virtual_address(x) ((x)->virtual_address) 103 | #define SEP_MMIO_NODE_map_token(x) ((x)->map_token) 104 | #define SEP_MMIO_NODE_size(x) ((x)->size) 105 | 106 | 107 | extern OS_STATUS 108 | PCI_Map_Memory ( 109 | SEP_MMIO_NODE *node, 110 | U64 phy_address, 111 | U32 map_size 112 | ); 113 | 114 | extern void 115 | PCI_Unmap_Memory ( 116 | SEP_MMIO_NODE *node 117 | ); 118 | 119 | extern int 120 | PCI_Read_From_Memory_Address ( 121 | U32 addr, 122 | U32* val 123 | ); 124 | 125 | extern int 126 | PCI_Write_To_Memory_Address ( 127 | U32 addr, 128 | U32 val 129 | ); 130 | 131 | 132 | 133 | /*** UNIVERSAL PCI ACCESSORS ***/ 134 | 135 | extern VOID PCI_Initialize ( 136 | VOID 137 | ); 138 | 139 | extern U32 PCI_Read_U32 ( 140 | U32 bus, 141 | U32 device, 142 | U32 function, 143 | U32 offset 144 | ); 145 | 146 | extern U32 PCI_Read_U32_Valid ( 147 | U32 bus, 148 | U32 device, 149 | U32 function, 150 | U32 offset, 151 | U32 invalid_value 152 | ); 153 | 154 | extern U64 PCI_Read_U64 ( 155 | U32 bus, 156 | U32 device, 157 | U32 function, 158 | U32 offset 159 | ); 160 | 161 | extern U64 PCI_Read_U64_Valid ( 162 | U32 bus, 163 | U32 device, 164 | U32 function, 165 | U32 offset, 166 | U64 invalid_value 167 | ); 168 | 169 | extern U32 PCI_Write_U32 ( 170 | U32 bus, 171 | U32 device, 172 | U32 function, 173 | U32 offset, 174 | U32 value 175 | ); 176 | 177 | extern U32 PCI_Write_U64 ( 178 | U32 bus, 179 | U32 device, 180 | U32 function, 181 | U32 offset, 182 | U64 value 183 | ); 184 | 185 | 186 | /*** UNIVERSAL MMIO ACCESSORS ***/ 187 | 188 | extern U32 189 | PCI_MMIO_Read_U32 ( 190 | U64 virtual_address_base, 191 | U32 offset 192 | ); 193 | 194 | extern U64 195 | PCI_MMIO_Read_U64 ( 196 | U64 virtual_address_base, 197 | U32 offset 198 | ); 199 | 200 | extern void 201 | PCI_MMIO_Write_U32 ( 202 | U64 virtual_address_base, 203 | U32 offset, 204 | U32 value 205 | ); 206 | 207 | extern void 208 | PCI_MMIO_Write_U64 ( 209 | U64 virtual_address_base, 210 | U32 offset, 211 | U64 value 212 | ); 213 | 214 | 215 | #endif 216 | 217 | -------------------------------------------------------------------------------- /sepdk/include/pax_shared.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | /* 30 | * 31 | * Description: types and definitions shared between PAX kernel 32 | * and user modes 33 | * 34 | * NOTE: alignment on page boundaries is required on 64-bit platforms! 35 | * 36 | */ 37 | 38 | 39 | #ifndef _PAX_SHARED_H_ 40 | #define _PAX_SHARED_H_ 41 | 42 | #include "lwpmudrv_defines.h" 43 | #include "lwpmudrv_types.h" 44 | 45 | #define _STRINGIFY(x) #x 46 | #define STRINGIFY(x) _STRINGIFY(x) 47 | 48 | // PAX versioning 49 | 50 | #define PAX_MAJOR_VERSION 1 // major version (increment only when PAX driver is incompatible with previous versions) 51 | #define PAX_MINOR_VERSION 0 // minor version (increment only when new APIs are added, but driver remains backwards compatible) 52 | #define PAX_BUGFIX_VERSION 2 // bugfix version (increment only for bug fixes that don't affect usermode/driver compatibility) 53 | 54 | #define PAX_VERSION_STR STRINGIFY(PAX_MAJOR_VERSION)"."STRINGIFY(PAX_MINOR_VERSION)"."STRINGIFY(PAX_BUGFIX_VERSION) 55 | 56 | // PAX device name 57 | 58 | #if defined(DRV_OS_WINDOWS) 59 | #define PAX_NAME "sepdal" 60 | #define PAX_NAME_W L"sepdal" 61 | #else 62 | #define PAX_NAME "pax" 63 | #endif 64 | 65 | // PAX PMU reservation states 66 | 67 | #define PAX_PMU_RESERVED 1 68 | #define PAX_PMU_UNRESERVED 0 69 | 70 | #define PAX_GUID_UNINITIALIZED 0 71 | 72 | // PAX_IOCTL definitions 73 | 74 | #if defined(DRV_OS_WINDOWS) 75 | 76 | // 77 | // The name of the device as seen by the driver 78 | // 79 | #define LSTRING(x) L#x 80 | #define PAX_OBJECT_DEVICE_NAME L"\\Device\\sepdal" // LSTRING(PAX_NAME) 81 | #define PAX_OBJECT_LINK_NAME L"\\DosDevices\\sepdal" // LSTRING(PAX_NAME) 82 | 83 | #define PAX_DEVICE_NAME PAX_NAME // for CreateFile called by app 84 | 85 | #define PAX_IOCTL_DEVICE_TYPE 0xA000 // values 0-32768 reserved for Microsoft 86 | #define PAX_IOCTL_FUNCTION 0xA00 // values 0-2047 reserved for Microsoft 87 | 88 | // 89 | // Basic CTL CODE macro to reduce typographical errors 90 | // 91 | #define PAX_CTL_READ_CODE(x) CTL_CODE(PAX_IOCTL_DEVICE_TYPE, \ 92 | PAX_IOCTL_FUNCTION+(x), \ 93 | METHOD_BUFFERED, \ 94 | FILE_READ_ACCESS) 95 | 96 | #define PAX_IOCTL_INFO PAX_CTL_READ_CODE(1) 97 | #define PAX_IOCTL_STATUS PAX_CTL_READ_CODE(2) 98 | #define PAX_IOCTL_RESERVE_ALL PAX_CTL_READ_CODE(3) 99 | #define PAX_IOCTL_UNRESERVE PAX_CTL_READ_CODE(4) 100 | 101 | #elif defined(DRV_OS_LINUX) || defined (DRV_OS_ANDROID) || defined (DRV_OS_SOLARIS) 102 | 103 | #define PAX_DEVICE_NAME "/dev/" PAX_NAME 104 | 105 | #define PAX_IOC_MAGIC 100 106 | #define PAX_IOCTL_INFO _IOW(PAX_IOC_MAGIC, 1, IOCTL_ARGS) 107 | #define PAX_IOCTL_STATUS _IOW(PAX_IOC_MAGIC, 2, IOCTL_ARGS) 108 | #define PAX_IOCTL_RESERVE_ALL _IO (PAX_IOC_MAGIC, 3) 109 | #define PAX_IOCTL_UNRESERVE _IO (PAX_IOC_MAGIC, 4) 110 | 111 | #if defined(HAVE_COMPAT_IOCTL) && defined(DRV_EM64T) 112 | #define PAX_IOCTL_COMPAT_INFO _IOW(PAX_IOC_MAGIC, 1, compat_uptr_t) 113 | #define PAX_IOCTL_COMPAT_STATUS _IOW(PAX_IOC_MAGIC, 2, compat_uptr_t) 114 | #define PAX_IOCTL_COMPAT_RESERVE_ALL _IO (PAX_IOC_MAGIC, 3) 115 | #define PAX_IOCTL_COMPAT_UNRESERVE _IO (PAX_IOC_MAGIC, 4) 116 | #endif 117 | 118 | #elif defined(DRV_OS_FREEBSD) 119 | 120 | #define PAX_DEVICE_NAME "/dev/" PAX_NAME 121 | 122 | #define PAX_IOC_MAGIC 100 123 | #define PAX_IOCTL_INFO _IOW(PAX_IOC_MAGIC, 1, IOCTL_ARGS_NODE) 124 | #define PAX_IOCTL_STATUS _IOW(PAX_IOC_MAGIC, 2, IOCTL_ARGS_NODE) 125 | #define PAX_IOCTL_RESERVE_ALL _IO (PAX_IOC_MAGIC, 3) 126 | #define PAX_IOCTL_UNRESERVE _IO (PAX_IOC_MAGIC, 4) 127 | 128 | #elif defined(DRV_OS_MAC) 129 | 130 | // OSX driver names are always in reverse DNS form. 131 | #define PAXDriverClassName com_intel_driver_PAX 132 | #define kPAXDriverClassName "com_intel_driver_PAX" 133 | #define PAX_DEVICE_NAME "com.intel.driver.PAX" 134 | 135 | // User client method dispatch selectors. 136 | enum { 137 | kPAXUserClientOpen, 138 | kPAXUserClientClose, 139 | kPAXReserveAll, 140 | kPAXUnreserve, 141 | kPAXGetStatus, 142 | kPAXGetInfo, 143 | kPAXDataIO, 144 | kNumberOfMethods // Must be last 145 | }; 146 | 147 | #else 148 | #warning "unknown OS in pax_shared.h" 149 | #endif 150 | 151 | // data for PAX_IOCTL_INFO call 152 | 153 | struct PAX_INFO_NODE_S { 154 | volatile U64 managed_by; // entity managing PAX 155 | volatile U32 version; // PAX version number 156 | volatile U64 reserved1; // force 8-byte alignment 157 | volatile U32 reserved2; // unreserved 158 | }; 159 | 160 | typedef struct PAX_INFO_NODE_S PAX_INFO_NODE; 161 | typedef PAX_INFO_NODE *PAX_INFO; 162 | 163 | // data for PAX_IOCTL_STATUS call 164 | 165 | struct PAX_STATUS_NODE_S { 166 | volatile U64 guid; // reservation ID (globally unique identifier) 167 | volatile DRV_FILE_DESC pid; // pid of process that has the reservation 168 | volatile U64 start_time; // reservation start time 169 | volatile U32 is_reserved; // 1 if there is a reservation, 0 otherwise 170 | }; 171 | 172 | typedef struct PAX_STATUS_NODE_S PAX_STATUS_NODE; 173 | typedef PAX_STATUS_NODE *PAX_STATUS; 174 | 175 | struct PAX_VERSION_NODE_S { 176 | union { 177 | U32 version; 178 | struct { 179 | U32 major:8; 180 | U32 minor:8; 181 | U32 bugfix:16; 182 | } s1; 183 | } u1; 184 | }; 185 | 186 | typedef struct PAX_VERSION_NODE_S PAX_VERSION_NODE; 187 | typedef PAX_VERSION_NODE *PAX_VERSION; 188 | 189 | #define PAX_VERSION_NODE_version(v) (v)->u1.version 190 | #define PAX_VERSION_NODE_major(v) (v)->u1.s1.major 191 | #define PAX_VERSION_NODE_minor(v) (v)->u1.s1.minor 192 | #define PAX_VERSION_NODE_bugfix(v) (v)->u1.s1.bugfix 193 | 194 | #endif 195 | 196 | -------------------------------------------------------------------------------- /sepdk/src/sys32.S: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2002-2019 Intel Corporation. All Rights Reserved. 2 | # 3 | # This file is part of SEP Development Kit 4 | # 5 | # SEP Development Kit is free software; you can redistribute it 6 | # and/or modify it under the terms of the GNU General Public License 7 | # version 2 as published by the Free Software Foundation. 8 | # 9 | # SEP Development Kit is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with SEP Development Kit; if not, write to the Free Software 16 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | # 18 | # As a special exception, you may use this file as part of a free software 19 | # library without restriction. Specifically, if other files instantiate 20 | # templates or use macros or inline functions from this file, or you compile 21 | # this file and link it with other files to produce an executable, this 22 | # file does not by itself cause the resulting executable to be covered by 23 | # the GNU General Public License. This exception does not however 24 | # invalidate any other reasons why the executable file might be covered by 25 | # the GNU General Public License. 26 | 27 | 28 | #include 29 | #include 30 | 31 | #if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,20) 32 | #define USE_KERNEL_PERCPU_SEGMENT_GS 33 | #endif 34 | 35 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) && LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,29) 36 | #define USE_KERNEL_PERCPU_SEGMENT_FS 37 | #endif 38 | 39 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) 40 | #define USE_KERNEL_PERCPU_SEGMENT_FS 41 | #define USE_KERNEL_PERCPU_SEGMENT_GS 42 | #endif 43 | 44 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) 45 | #if !defined(__KERNEL_PERCPU) 46 | #define __KERNEL_PERCPU __KERNEL_PDA 47 | #endif 48 | #endif 49 | 50 | #if defined(USE_KERNEL_PERCPU_SEGMENT_GS) 51 | #if defined(__KERNEL_STACK_CANARY) 52 | #define SEP_GS_SEG_VALUE __KERNEL_STACK_CANARY 53 | #else 54 | #define SEP_GS_SEG_VALUE __KERNEL_PERCPU 55 | #endif 56 | #endif 57 | 58 | #*********************************************************************** 59 | # 60 | # SYS_IO_Delay 61 | # Add small delay 62 | # 63 | # Entry: none 64 | # 65 | # Exit: none 66 | # 67 | # void SYS_IO_Delay(); 68 | # 69 | #*********************************************************************** 70 | .text 71 | .align 4 72 | .global SYS_IO_Delay 73 | SYS_IO_Delay: 74 | ret 75 | 76 | .global SYS_Get_cs 77 | SYS_Get_cs: 78 | mov %cs, %ax 79 | andl $0x0000ffff, %eax 80 | ret 81 | 82 | .global SYS_Get_TSC 83 | SYS_Get_TSC: 84 | rdtsc 85 | ret 86 | .text 87 | .align 4 88 | .global SYS_Perfvec_Handler 89 | SYS_Perfvec_Handler: 90 | # This is the same as KERNEL's 91 | pushl %eax # Filler for Error Code 92 | 93 | cld 94 | pushl %es # SAVE_ALL macro to access pt_regs 95 | pushl %ds # inside our ISR. 96 | #if defined(USE_KERNEL_PERCPU_SEGMENT_GS) 97 | pushl %gs 98 | #endif 99 | #if defined(USE_KERNEL_PERCPU_SEGMENT_FS) 100 | pushl %fs 101 | #endif 102 | pushl %eax 103 | pushl %ebp 104 | pushl %edi 105 | pushl %esi 106 | pushl %edx 107 | pushl %ecx 108 | pushl %ebx 109 | 110 | movl $(__KERNEL_DS), %edx # Use KERNEL DS selector 111 | movl %edx,%ds # Make sure we set Kernel 112 | movl %edx,%es # DS into local DS and ES 113 | 114 | #if defined(USE_KERNEL_PERCPU_SEGMENT_GS) 115 | movl $(SEP_GS_SEG_VALUE), %edx # Use kernel percpu segment 116 | movl %edx,%gs # ... and load it into %gs 117 | #endif 118 | #if defined(USE_KERNEL_PERCPU_SEGMENT_FS) 119 | movl $(__KERNEL_PERCPU), %edx # Use kernel percpu segment 120 | movl %edx,%fs # ... and load it into %fs 121 | #endif 122 | 123 | movl %esp, %ebx # get ready to put *pt_regs on stack 124 | 125 | pushl %ebx # put *pt_regs on the stack 126 | call PMI_Interrupt_Handler 127 | addl $0x4, %esp # pop to nowhere... 128 | 129 | pop %ebx # restore register set 130 | pop %ecx 131 | pop %edx 132 | pop %esi 133 | pop %edi 134 | pop %ebp 135 | pop %eax 136 | #if defined(USE_KERNEL_PERCPU_SEGMENT_FS) 137 | pop %fs 138 | #endif 139 | #if defined(USE_KERNEL_PERCPU_SEGMENT_GS) 140 | pop %gs 141 | #endif 142 | pop %ds 143 | pop %es 144 | pop %eax 145 | 146 | iret 147 | # ---------------------------------------------------------------------------- 148 | # name: get_CSD 149 | # 150 | # description: get the CS descriptor 151 | # 152 | # input: code segment selector 153 | # 154 | # output: code segment descriptor 155 | # ---------------------------------------------------------------------------- 156 | .text 157 | .align 4 158 | .globl SYS_Get_CSD 159 | 160 | SYS_Get_CSD: 161 | pushl %ebp 162 | movl %esp, %ebp 163 | pushal # save regs 164 | 165 | subl $8,%esp 166 | xorl %eax, %eax 167 | movw 8(%ebp), %ax # eax.lo = cs 168 | sgdt (%esp) # store gdt reg 169 | leal (%esp), %ebx # ebx = gdt reg ptr 170 | movl 2(%ebx), %ecx # ecx = gdt base 171 | xorl %edx, %edx 172 | movw %ax, %dx 173 | andl $4, %edx 174 | cmpl $0, %edx # test ti. GDT? 175 | jz .bsr_10 # ..yes 176 | xorl %edx, %edx 177 | sldt %dx # ..no dx=ldtsel 178 | andb $0xf8, %dl # clear ti,rpl 179 | addl 2(%ebx), %edx # add gdt base 180 | movb 7(%edx), %cl # ecx = ldt base 181 | shll $8, %ecx # .. 182 | movb 4(%edx), %cl # .. 183 | shll $16, %ecx # .. 184 | movw 2(%edx), %cx # .. 185 | .bsr_10: 186 | andb $0xf8, %al # clear ti & rpl 187 | addl %eax, %ecx # add to gdt/ldt 188 | movl (%ecx), %eax # copy code seg 189 | movl 12(%ebp), %edx # ..descriptor (csdlo) 190 | movl %eax, (%edx) # ..descriptor (csdlo) 191 | movl 4(%ecx), %eax # ..from gdt or 192 | movl 16(%ebp), %edx # ..ldt to sample (csdhi) 193 | movl %eax, (%edx) # ..ldt to sample (csdhi) 194 | addl $8,%esp 195 | popal # restore regs 196 | leave 197 | ret 198 | -------------------------------------------------------------------------------- /agentdk/communication.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #ifndef _COMMUNICATION_H_ 30 | #define _COMMUNICATION_H_ 31 | 32 | #if defined(__cplusplus) 33 | extern "C" { 34 | #endif 35 | 36 | 37 | #define PROTOCOL_VERSION 6 38 | #define DEFAULT_CONTROL_PORT 9321 39 | #define DEFAULT_MSG_BUFFER_SIZE 4096 40 | #define DEFAULT_CONNECTION_TIMEOUT 60 41 | #define NUM_NONCORE_DATA_CONNECTIONS 2 42 | #define MAX_NUM_CPUS 64 43 | 44 | /* Maximum number of data connections = MAX_NUM_CPUS (1 per CPU for core data) + 45 | NUM_NONCORE_DATA_CONNECTIONS ( 1 for module and 1 for uncore data) + MAX_NUM_CPUS (1 per CPU for sideband data) */ 46 | #define MAX_DATA_CONNECTION (2*MAX_NUM_CPUS+NUM_NONCORE_DATA_CONNECTIONS) 47 | #define MODULE_DATA_CONNECTION MAX_NUM_CPUS 48 | #define UNCORE_DATA_CONNECTION (MAX_NUM_CPUS+1) 49 | #define SIDEBAND_DATA_CONN_OFFSET (MAX_NUM_CPUS+2) 50 | #define CONTROL_SOCKET_RECV_BUF_SIZE 128 51 | #define COMM_MODULE_CONN_ID 0 52 | #define COMM_UNCORE_CONN_ID 0 53 | #define COMM_RECV_MAX_TIME_ALLOWED 30 54 | 55 | // to send large data without significant wait/hang on send(), increase the socket send buf size by setting SO_SNDBUF to 1MB 56 | #define DATA_SOCKET_SEND_BUF_SIZE (1 << 20) 57 | 58 | /* 59 | * Print macros for messages 60 | */ 61 | #define SEPAGENT_NAME "sepagent" 62 | #define SEPAGENT_MAJOR_VERSION 1 63 | #define SEPAGENT_MINOR_VERSION 0 64 | #define SEPAGENT_MSG_PREFIX SEPAGENT_NAME""STRINGIFY(SEPAGENT_MAJOR_VERSION)"_"STRINGIFY(SEPAGENT_MINOR_VERSION)":" 65 | 66 | 67 | 68 | typedef struct CONTROL_FIRST_MSG_NODE_S CONTROL_FIRST_MSG_NODE; 69 | typedef CONTROL_FIRST_MSG_NODE *CONTROL_FIRST_MSG; 70 | 71 | struct CONTROL_FIRST_MSG_NODE_S { 72 | U32 msg_size; 73 | U32 proto_version; 74 | U32 per_cpu_buffer_size; 75 | U32 reserved1; 76 | U64 reserved2; 77 | }; 78 | 79 | #define CONTROL_FIRST_MSG_msg_size(msg) (msg)->msg_size 80 | #define CONTROL_FIRST_MSG_proto_version(msg) (msg)->proto_version 81 | #define CONTROL_FIRST_MSG_per_cpu_buffer_size(msg) (msg)->per_cpu_buffer_size 82 | 83 | typedef struct TARGET_STATUS_MSG_NODE_S TARGET_STATUS_MSG_NODE; 84 | typedef TARGET_STATUS_MSG_NODE *TARGET_STATUS_MSG; 85 | 86 | struct TARGET_STATUS_MSG_NODE_S { 87 | struct { 88 | U32 msg_size; 89 | U32 proto_version; 90 | S32 status; 91 | U32 reserved1; 92 | U64 reserved2; 93 | U32 os_info_offset; 94 | U32 os_info_size; 95 | U32 collect_switch_offset; 96 | U32 collect_switch_size; 97 | U32 hardware_info_offset; 98 | U32 hardware_info_size; 99 | } s1; 100 | REMOTE_OS_INFO_NODE os_info; 101 | REMOTE_SWITCH_NODE collect_switch; 102 | REMOTE_HARDWARE_INFO_NODE hardware_info; 103 | }; 104 | 105 | #define TARGET_STATUS_MSG_msg_size(msg) (msg)->s1.msg_size 106 | #define TARGET_STATUS_MSG_proto_version(msg) (msg)->s1.proto_version 107 | #define TARGET_STATUS_MSG_status(msg) (msg)->s1.status 108 | #define TARGET_STATUS_MSG_os_info_offset(msg) (msg)->s1.os_info_offset 109 | #define TARGET_STATUS_MSG_collect_switch_offset(msg) (msg)->s1.collect_switch_offset 110 | #define TARGET_STATUS_MSG_hardware_info_offset(msg) (msg)->s1.hardware_info_offset 111 | #define TARGET_STATUS_MSG_os_info_size(msg) (msg)->s1.os_info_size 112 | #define TARGET_STATUS_MSG_collect_switch_size(msg) (msg)->s1.collect_switch_size 113 | #define TARGET_STATUS_MSG_hardware_info_size(msg) (msg)->s1.hardware_info_size 114 | #define TARGET_STATUS_MSG_os_info(msg) (msg)->os_info 115 | #define TARGET_STATUS_MSG_collect_switch(msg) (msg)->collect_switch 116 | #define TARGET_STATUS_MSG_hardware_info(msg) (msg)->hardware_info 117 | 118 | 119 | typedef struct CONTROL_MSG_HEADER_NODE_S CONTROL_MSG_HEADER_NODE; 120 | typedef CONTROL_MSG_HEADER_NODE *CONTROL_MSG_HEADER; 121 | 122 | struct CONTROL_MSG_HEADER_NODE_S { 123 | U32 header_size; 124 | U32 proto_version; 125 | U32 command_id; 126 | S32 status; 127 | U64 to_target_data_size; 128 | U64 from_target_data_size; 129 | U64 reserved1; 130 | U64 reserved2; 131 | }; 132 | 133 | #define CONTROL_MSG_HEADER_header_size(msg) (msg)->header_size 134 | #define CONTROL_MSG_HEADER_proto_version(msg) (msg)->proto_version 135 | #define CONTROL_MSG_HEADER_command_id(msg) (msg)->command_id 136 | #define CONTROL_MSG_HEADER_status(msg) (msg)->status 137 | #define CONTROL_MSG_HEADER_to_target_data_size(msg) (msg)->to_target_data_size 138 | #define CONTROL_MSG_HEADER_from_target_data_size(msg) (msg)->from_target_data_size 139 | 140 | 141 | typedef enum { 142 | COMM_DATA_CPU = 0, 143 | COMM_DATA_MODULE, 144 | COMM_DATA_UNCORE, 145 | COMM_DATA_SIDEBAND 146 | } COMM_DATA_TYPE; 147 | 148 | typedef struct DATA_FIRST_MSG_NODE_S DATA_FIRST_MSG_NODE; 149 | typedef DATA_FIRST_MSG_NODE *DATA_FIRST_MSG; 150 | 151 | struct DATA_FIRST_MSG_NODE_S { 152 | U32 proto_version; 153 | U16 data_type; 154 | U16 data_id; 155 | }; 156 | 157 | #define DATA_FIRST_MSG_proto_version(msg) (msg)->proto_version 158 | #define DATA_FIRST_MSG_data_type(msg) (msg)->data_type 159 | #define DATA_FIRST_MSG_data_id(msg) (msg)->data_id 160 | 161 | S32 COMM_Open_Control_On_Target(DRV_BOOL mode, U64 cpuid_rax, U64 tsc_freq, U32 agent_mode, U32 transfer_mode, U32 num_cpus); 162 | S32 COMM_Receive_Control_Request_On_Target(U32 *cmd, IOCTL_ARGS ioctl_arg, S32 trace_idx); 163 | S32 COMM_Send_Control_Response_On_Target(U32 cmd, IOCTL_ARGS ioctl_arg, S32 status, DRV_BOOL record_mode, S32 trace_idx); 164 | S32 COMM_Close_Control_On_Target(); 165 | S32 COMM_Open_Data_On_Target(U32 conn_id, U32 conn_type); 166 | S32 COMM_Send_Data_On_Target(U32 conn_id, U32 conn_type, void *buffer, S32 buffer_size); 167 | S32 COMM_Close_Data_On_Target(U32 conn_id, U32 conn_type); 168 | 169 | #if defined(__cplusplus) 170 | } 171 | #endif 172 | 173 | #endif 174 | 175 | -------------------------------------------------------------------------------- /sepdk/src/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Version: 1.6 3 | # 4 | # Copyright (C) 2008-2019 Intel Corporation. All Rights Reserved. 5 | # 6 | # This file is part of SEP Development Kit 7 | # 8 | # SEP Development Kit is free software; you can redistribute it 9 | # and/or modify it under the terms of the GNU General Public License 10 | # version 2 as published by the Free Software Foundation. 11 | # 12 | # SEP Development Kit is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with SEP Development Kit; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | # 21 | # As a special exception, you may use this file as part of a free software 22 | # library without restriction. Specifically, if other files instantiate 23 | # templates or use macros or inline functions from this file, or you compile 24 | # this file and link it with other files to produce an executable, this 25 | # file does not by itself cause the resulting executable to be covered by 26 | # the GNU General Public License. This exception does not however 27 | # invalidate any other reasons why the executable file might be covered by 28 | # the GNU General Public License. 29 | # 30 | 31 | # -------------------- user configurable options ------------------------ 32 | 33 | # base name of SEP driver 34 | DRIVER_NAME = sep5 35 | 36 | # location to install driver 37 | ifeq ($(INSTALL),) 38 | INSTALL = . 39 | endif 40 | 41 | # current working directory 42 | DRV_CWD := $(shell pwd) 43 | 44 | # If KERNELRELEASE is defined, we've been invoked from the 45 | # kernel build system and can use its language. 46 | # Example flags are "-Werror", "-Wno-error", etc. 47 | EXTRA_CFLAGS += -I$(LDDINCDIR) -I$(LDDINCDIR1) 48 | 49 | # if ARCH variable is set, unset it to avoid conflicts with kbuild 50 | unexport ARCH 51 | 52 | # platform details 53 | MACH ?= $(shell uname -m) 54 | export MACH 55 | ifeq ($(MACH),x86_64) 56 | PLATFORM=x32_64 57 | endif 58 | ifeq ($(PLATFORM),) 59 | PLATFORM=x32 60 | endif 61 | KERNEL_VERSION ?= $(shell uname -r) 62 | SMP ?= $(shell uname -v | grep SMP) 63 | ARITY=up 64 | ifneq ($(SMP),) 65 | ARITY=smp 66 | endif 67 | 68 | ifeq ($(PER_USER_MODE),YES) 69 | SEP_PER_USER=-pu 70 | endif 71 | 72 | 73 | # this is a temporary work-around for handling the module structure changes across multiple kernels. 74 | # need to find out a proper solution. 75 | ifneq ($(KERNEL_SRC_DIR),) 76 | PATH_PREFIX = $(KERNEL_SRC_DIR) 77 | endif 78 | PATH_PREFIX ?= /lib/modules/$(shell uname -r)/build 79 | ifneq ($(shell grep -s $(PATH_PREFIX)/include/linux/module.h -we "struct module_layout"),) 80 | EXTRA_CFLAGS += -DSEP_CONFIG_MODULE_LAYOUT 81 | endif 82 | 83 | ifeq ($(shell test -e $(PATH_PREFIX)/include/linux/kaiser.h && echo -n YES),YES) 84 | EXTRA_CFLAGS += -DKAISER_HEADER_PRESENT 85 | endif 86 | 87 | # eventual filename of SEP driver 88 | DRIVER_MODE=$(DRIVER_NAME)$(SEP_PER_USER) 89 | DRIVER_TYPE=$(PLATFORM)-$(KERNEL_VERSION)$(ARITY) 90 | DRIVER_FILENAME=$(DRIVER_MODE)-$(DRIVER_TYPE).ko 91 | 92 | # build options ... 93 | ifneq ($(KERNELRELEASE),) 94 | obj-m := $(DRIVER_NAME).o 95 | 96 | ifeq ($(PLATFORM),x32) 97 | arch-objs := core2.o \ 98 | perfver4.o \ 99 | sys32.o \ 100 | silvermont.o \ 101 | pci.o \ 102 | apic.o \ 103 | pebs.o \ 104 | unc_gt.o \ 105 | unc_mmio.o \ 106 | unc_msr.o \ 107 | unc_common.o \ 108 | unc_pci.o \ 109 | sepdrv_p_state.o 110 | endif 111 | ifeq ($(PLATFORM),x32_64) 112 | arch-objs := core2.o \ 113 | perfver4.o \ 114 | sys64.o \ 115 | silvermont.o \ 116 | pci.o \ 117 | apic.o \ 118 | pebs.o \ 119 | unc_gt.o \ 120 | unc_mmio.o \ 121 | unc_msr.o \ 122 | unc_common.o \ 123 | unc_pci.o \ 124 | sepdrv_p_state.o 125 | endif 126 | 127 | ifeq ($(PER_USER_MODE),YES) 128 | EXTRA_CFLAGS += -DSECURE_SEP 129 | endif 130 | 131 | EXTRA_CFLAGS += -DDRV_CPU_HOTPLUG -DDRV_USE_TASKLET_WORKAROUND -DDRV_SAFE_MSR -DDRV_DISABLE_PEBS 132 | 133 | ifeq ($(MINLOG_MODE),YES) 134 | EXTRA_CFLAGS += -DDRV_MINIMAL_LOGGING 135 | $(info **********************************************************************************) 136 | $(info WARNING: Using minimal logging mode. This may make troubleshooting more difficult.) 137 | $(info **********************************************************************************) 138 | else 139 | ifeq ($(MAXLOG_MODE),YES) 140 | EXTRA_CFLAGS += -DDRV_MAXIMAL_LOGGING 141 | $(info ****************************************************************) 142 | $(info WARNING: Using maximal logging mode. This may increase overhead.) 143 | $(info ****************************************************************) 144 | endif 145 | endif 146 | 147 | ifeq ($(UDEV_AVAILABLE),NO) 148 | EXTRA_CFLAGS += -DDRV_UDEV_UNAVAILABLE 149 | $(info ********************************************************************************) 150 | $(info WARNING: The device manager is NOT available. It create device files separately.) 151 | $(info ********************************************************************************) 152 | endif 153 | EXTRA_CFLAGS += -DDISABLE_BUILD_SOCPERF 154 | #** 155 | ifeq ($(BUILD_PUBLIC),YES) 156 | else 157 | EXTRA_CFLAGS += -DENABLE_CPUS 158 | private-objs := unc_sa.o 159 | endif 160 | 161 | #== 162 | 163 | $(DRIVER_NAME)-objs := \ 164 | lwpmudrv.o \ 165 | control.o \ 166 | cpumon.o \ 167 | eventmux.o \ 168 | linuxos.o \ 169 | output.o \ 170 | pmi.o \ 171 | sys_info.o \ 172 | utility.o \ 173 | valleyview_sochap.o \ 174 | unc_power.o \ 175 | pmu_list.o \ 176 | $(private-objs) \ 177 | $(arch-objs) 178 | 179 | # targets ... 180 | 181 | # Otherwise, we were called directly from the command 182 | # line, so the kernel build system will be used. 183 | else 184 | KERNEL_SRC_DIR ?= /lib/modules/$(shell uname -r)/build 185 | PWD := $(shell pwd) 186 | 187 | all: default 188 | 189 | default: 190 | $(MAKE) -C $(KERNEL_SRC_DIR) M=$(PWD) LDDINCDIR=$(PWD)/../include LDDINCDIR1=$(PWD)/inc modules PWD=$(PWD) -j4 191 | cp $(DRIVER_NAME).ko $(DRIVER_FILENAME) 192 | 193 | endif 194 | 195 | install: 196 | @if [ $(DRV_CWD) != $(INSTALL) ] ; then \ 197 | cp $(DRIVER_FILENAME) $(INSTALL)/$(DRIVER_FILENAME) ; \ 198 | cp insmod-sep $(INSTALL)/insmod-sep ; \ 199 | cp rmmod-sep $(INSTALL)/rmmod-sep ; \ 200 | cp boot-script $(INSTALL)/boot-script ; \ 201 | cp read_dmisysfs.py $(INSTALL)/read_dmisysfs.py ; \ 202 | cp read_slitsysfs.py $(INSTALL)/read_slitsysfs.py ; \ 203 | cp read_sratsysfs.py $(INSTALL)/read_sratsysfs.py ; \ 204 | cp read_smbios.py $(INSTALL)/read_smbios.py ; \ 205 | echo "Installed $(DRIVER_NAME) driver to $(INSTALL)/$(DRIVER_FILENAME) ." ; \ 206 | fi; 207 | 208 | 209 | clean: 210 | rm -f *.o .*.o.cmd .*.o.d .*.ko.cmd .*.ko.unsigned.cmd *.gcno .cache.mk *.o.ur-safe .*.o.tmp 211 | rm -f $(DRIVER_NAME).ko $(DRIVER_NAME).ko.unsigned 212 | rm -f $(DRIVER_MODE)*$(DRIVER_TYPE).ko 213 | rm -f Module.symvers Modules.symvers *.mod.c modules.order Module.markers 214 | rm -rf .tmp_versions 215 | 216 | distclean: clean 217 | rm -f $(DRIVER_NAME)*.ko 218 | 219 | -------------------------------------------------------------------------------- /agentdk/abstract.h: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | /* 30 | * File : abstract.h 31 | */ 32 | 33 | #ifndef _ABSTRACT_H_INC_ 34 | #define _ABSTRACT_H_INC_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | 41 | #if defined(DRV_OS_ANDROID) 42 | #define OUT_BUF_SIZE 16 43 | #endif 44 | 45 | #if defined(DRV_OS_LINUX) || defined(DRV_OS_SOLARIS) || defined(DRV_OS_MAC) || defined(DRV_OS_FREEBSD) 46 | #define OUT_BUF_SIZE 17 47 | #endif 48 | 49 | typedef struct OSI_THREAD_NODE_S OSI_THREAD_NODE; 50 | typedef OSI_THREAD_NODE *OSI_THREAD; 51 | struct OSI_THREAD_NODE_S { 52 | pthread_t thread; 53 | pthread_attr_t attr; 54 | }; 55 | 56 | #define OSI_THREAD_thread(opt) (opt)->thread 57 | #define OSI_THREAD_attr(opt) (opt)->attr 58 | 59 | 60 | /* 61 | * Structures used to manage Read Threads 62 | */ 63 | #define THREAD_ARG_SIZE MAXNAMELEN 64 | typedef struct THREAD_ARG_NODE_S THREAD_ARG_NODE; 65 | typedef THREAD_ARG_NODE *THREAD_ARG; 66 | struct THREAD_ARG_NODE_S { 67 | S32 me; 68 | char dname[THREAD_ARG_SIZE]; 69 | char oname[THREAD_ARG_SIZE]; 70 | int dev_id; 71 | int epd; 72 | U32 buf_size; 73 | void *dma_buf; 74 | U32 conn_id; 75 | U32 conn_type; 76 | }; 77 | 78 | #define THREAD_ARG_me(targ) (targ)->me 79 | #define THREAD_ARG_dname(targ) (targ)->dname 80 | #define THREAD_ARG_oname(targ) (targ)->oname 81 | #define THREAD_ARG_epd(targ) (targ)->epd 82 | #define THREAD_ARG_dma_buf(targ) (targ)->dma_buf 83 | #define THREAD_ARG_buf_size(targ) (targ)->buf_size 84 | #define THREAD_ARG_dev_id(targ) (targ)->dev_id 85 | #define THREAD_ARG_conn_id(targ) (targ)->conn_id 86 | #define THREAD_ARG_conn_type(targ) (targ)->conn_type 87 | 88 | 89 | typedef struct READ_THREAD_NODE_S READ_THREAD_NODE; 90 | typedef READ_THREAD_NODE *READ_THREAD; 91 | struct READ_THREAD_NODE_S { 92 | OSI_THREAD_NODE tn; 93 | THREAD_ARG_NODE arg; 94 | }; 95 | 96 | #define READ_THREAD_tn(rt) (rt)->tn 97 | #define READ_THREAD_arg(rt) (rt)->arg 98 | 99 | #define READ_THREAD_thread(rt) OSI_THREAD_thread(&(READ_THREAD_tn((rt)))) 100 | #define READ_THREAD_attr(rt) OSI_THREAD_attr(&(READ_THREAD_tn((rt)))) 101 | 102 | #define READ_THREAD_me(rt) THREAD_ARG_me(&(READ_THREAD_arg((rt)))) 103 | #define READ_THREAD_dname(rt) THREAD_ARG_dname(&(READ_THREAD_arg((rt)))) 104 | #define READ_THREAD_oname(rt) THREAD_ARG_oname(&(READ_THREAD_arg((rt)))) 105 | #define READ_THREAD_epd(rt) THREAD_ARG_epd(&(READ_THREAD_arg((rt)))) 106 | #define READ_THREAD_dma_buf(rt) THREAD_ARG_dma_buf(&(READ_THREAD_arg((rt)))) 107 | #define READ_THREAD_buf_size(rt) THREAD_ARG_buf_size(&(READ_THREAD_arg((rt)))) 108 | #define READ_THREAD_dev_id(rt) THREAD_ARG_dev_id(&(READ_THREAD_arg((rt)))) 109 | #define READ_THREAD_conn_id(rt) THREAD_ARG_conn_id(&(READ_THREAD_arg((rt)))) 110 | #define READ_THREAD_conn_type(rt) THREAD_ARG_conn_type(&(READ_THREAD_arg((rt)))) 111 | 112 | /* 113 | * @fn abstract_Start_Threads() 114 | * 115 | * @brief All core buffers and temp files are set up 116 | * and the system will be prepared to start sampling. 117 | * It must be called just before DRV_OPERATION_INIT_DRIVER. 118 | * It must also be called just once per collector session. 119 | * @param None 120 | * 121 | * @return Status 122 | */ 123 | static DRV_STATUS 124 | abstract_Start_Threads ( 125 | S8 *pcfg_buf 126 | ); 127 | 128 | /* 129 | * @fn abstract_Start_Threads_UNC() 130 | * 131 | * @brief All uncore buffers and temp files for uncore are set up 132 | * and the system will be prepared to start sampling. 133 | * It must be called just before DRV_OPERATION_INIT_UNC. 134 | * This must also be called just once per sampling session. 135 | * 136 | * @param None 137 | * 138 | * @return Status 139 | */ 140 | static DRV_STATUS 141 | abstract_Start_Threads_UNC ( 142 | U32 num_packages 143 | ); 144 | 145 | /* 146 | * @fn abstract_Stop_Threads() 147 | * 148 | * @brief Stop threads - core and uncore. 149 | * 150 | * @param None 151 | * 152 | * @return Status 153 | */ 154 | static DRV_STATUS 155 | abstract_Stop_Threads ( 156 | ); 157 | 158 | /* 159 | * @fn abstract_Set_OSID(S8 *buf) 160 | * 161 | * @brief set osid 162 | * 163 | * @param IN osid - pointer to osid 164 | * 165 | * @return None 166 | */ 167 | static VOID 168 | abstract_Set_OSID( 169 | S8 *buf 170 | ); 171 | 172 | 173 | /* 174 | * @fn ABSTRACT_Num_CPUs (num_cpus) 175 | * 176 | * @param U32 *num_cpus - number of CPUs 177 | * 178 | * @brief Retrieve number of cores in system 179 | * 180 | * @return DRV_STATUS - VT_SUCCESS on success 181 | */ 182 | DRV_DLLEXPORT DRV_STATUS 183 | ABSTRACT_Num_CPUs ( 184 | U32 *num_cpus 185 | ); 186 | 187 | 188 | /* 189 | * @fn ABSTRACT_Version (void) 190 | * 191 | * @param void 192 | * 193 | * @return U32 - The version number of the kernel mode driver. 194 | * 195 | * @brief return the version number of the driver 196 | */ 197 | DRV_DLLEXPORT U32 198 | ABSTRACT_Version ( 199 | void 200 | ); 201 | 202 | 203 | /* 204 | * @fn U32 ABSTRACT_Get_Agent_Mode ( U32 *agent_mode, U32 transfer_mode ) 205 | * 206 | * @brief Get sep driver mode (Native/Guest VM/Host VM) 207 | * 208 | * @param OUT agent_mode - agent mode 209 | * IN data_transfer_mode - transfer mode 210 | * 211 | * @return Status 212 | * 213 | * Special Notes: 214 | * 215 | */ 216 | DRV_DLLEXPORT U32 217 | ABSTRACT_Get_Agent_Mode ( 218 | U32 *agent_mode, 219 | U32 transfer_mode 220 | ); 221 | 222 | 223 | /* 224 | * @fn ABSTRACT_Check_KVM_Enabled 225 | * 226 | * @brief Check if the KVM is enabled 227 | * 228 | * @param None 229 | * 230 | * @return DRV_BOOL KVM enable status 231 | * 232 | * Special Notes: 233 | * < None > 234 | */ 235 | DRV_DLLEXPORT DRV_BOOL 236 | ABSTRACT_Check_KVM_Enabled ( 237 | void 238 | ); 239 | 240 | 241 | /* 242 | * @fn ABSTRACT_Get_Drv_Setup_Info() 243 | * 244 | * @brief Get numerous information from driver. 245 | * 246 | * @param DRV_SETUP_INFO drv_setup_info 247 | * 248 | * @return Status 249 | */ 250 | DRV_DLLEXPORT DRV_STATUS 251 | ABSTRACT_Get_Drv_Setup_Info ( 252 | DRV_SETUP_INFO drv_setup_info 253 | ); 254 | 255 | #ifdef __cplusplus 256 | } 257 | 258 | #endif 259 | 260 | #endif 261 | -------------------------------------------------------------------------------- /sepdk/src/inc/unc_common.h: -------------------------------------------------------------------------------- 1 | /*COPYRIGHT** 2 | Copyright (C) 2012-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | **COPYRIGHT*/ 28 | 29 | 30 | 31 | 32 | 33 | #ifndef _UNC_COMMON_H_INC_ 34 | #define _UNC_COMMON_H_INC_ 35 | 36 | #include "pci.h" 37 | 38 | #define DRV_IS_PCI_VENDOR_ID_INTEL 0x8086 39 | #define VENDOR_ID_MASK 0x0000FFFF 40 | #define DEVICE_ID_MASK 0xFFFF0000 41 | #define DEVICE_ID_BITSHIFT 16 42 | 43 | #define UNCORE_SOCKETID_UBOX_LNID_OFFSET 0x40 44 | #define UNCORE_SOCKETID_UBOX_GID_OFFSET 0x54 45 | 46 | #define INVALID_BUS_NUMBER -1 47 | #define PCI_INVALID_VALUE 0xFFFFFFFF 48 | 49 | typedef struct DEVICE_CALLBACK_NODE_S DEVICE_CALLBACK_NODE; 50 | typedef DEVICE_CALLBACK_NODE *DEVICE_CALLBACK; 51 | 52 | struct DEVICE_CALLBACK_NODE_S { 53 | DRV_BOOL (*is_Valid_Device)(U32); 54 | DRV_BOOL (*is_Valid_For_Write)(U32, U32); 55 | DRV_BOOL (*is_Unit_Ctl)(U32); 56 | DRV_BOOL (*is_PMON_Ctl)(U32); 57 | }; 58 | 59 | 60 | #define MAX_PCIDEV_UNITS 16 61 | #define GET_MAX_PCIDEV_ENTRIES(num_pkg) ((num_pkg>MAX_PCIDEV_UNITS)? num_pkg:MAX_PCIDEV_UNITS) 62 | 63 | typedef struct UNC_PCIDEV_NODE_S UNC_PCIDEV_NODE; 64 | 65 | struct UNC_PCIDEV_NODE_S { 66 | U32 num_entries; 67 | U32 max_entries; 68 | S32 *busno_list; // array for pcibus mapping 69 | SEP_MMIO_NODE *mmio_map; // virtual memory mapping entries 70 | U32 num_mmio_main_bar_per_entry; 71 | U32 num_mmio_secondary_bar_per_entry; 72 | }; 73 | 74 | #define UNC_PCIDEV_max_entries(x) ((x)->max_entries) 75 | #define UNC_PCIDEV_num_entries(x) ((x)->num_entries) 76 | #define UNC_PCIDEV_busno_list(x) ((x)->busno_list) 77 | #define UNC_PCIDEV_busno_entry(x, entry) ((x)->busno_list[entry]) 78 | #define UNC_PCIDEV_mmio_map(x) ((x)->mmio_map) 79 | #define UNC_PCIDEV_mmio_map_entry(x, entry) ((x)->mmio_map[entry]) 80 | #define UNC_PCIDEV_num_mmio_main_bar_per_entry(x) ((x)->num_mmio_main_bar_per_entry) 81 | #define UNC_PCIDEV_num_mmio_secondary_bar_per_entry(x) ((x)->num_mmio_secondary_bar_per_entry) 82 | #define UNC_PCIDEV_virtual_addr_entry(x, entry) (SEP_MMIO_NODE_virtual_address(&UNC_PCIDEV_mmio_map_entry(x, entry))) 83 | 84 | #define UNC_PCIDEV_is_busno_valid(x, entry) (((x)->busno_list) && ((x)->num_entries > (entry)) && ((x)->busno_list[(entry)] != INVALID_BUS_NUMBER)) 85 | #define UNC_PCIDEV_is_vaddr_valid(x, entry) (((x)->mmio_map) && \ 86 | ((x)->num_entries * (x)->num_mmio_secondary_bar_per_entry > (entry)) && \ 87 | ((x)->mmio_map[(entry)].virtual_address)) 88 | 89 | extern UNC_PCIDEV_NODE unc_pcidev_map[]; 90 | 91 | #define GET_BUS_MAP(dev_node, entry) (UNC_PCIDEV_busno_entry((&(unc_pcidev_map[dev_node])), entry)) 92 | #define GET_NUM_MAP_ENTRIES(dev_node) (UNC_PCIDEV_num_entries(&(unc_pcidev_map[dev_node]))) 93 | #define GET_NUM_MMIO_SECONDARY_BAR(dev_node) (UNC_PCIDEV_num_mmio_secondary_bar_per_entry(&(unc_pcidev_map[dev_node]))) 94 | #define IS_MMIO_MAP_VALID(dev_node, entry) (UNC_PCIDEV_is_vaddr_valid((&(unc_pcidev_map[dev_node])), entry)) 95 | #define IS_BUS_MAP_VALID(dev_node, entry) (UNC_PCIDEV_is_busno_valid((&(unc_pcidev_map[dev_node])), entry)) 96 | #define virtual_address_table(dev_node, entry) (UNC_PCIDEV_virtual_addr_entry(&(unc_pcidev_map[dev_node]), entry)) 97 | 98 | 99 | 100 | 101 | extern OS_STATUS 102 | UNC_COMMON_Do_Bus_to_Socket_Map( 103 | U32 uncore_did, 104 | U32 dev_node, 105 | U32 bus_no, 106 | U32 device_no, 107 | U32 function_no 108 | ); 109 | 110 | 111 | extern VOID 112 | UNC_COMMON_Dummy_Func( 113 | PVOID param 114 | ); 115 | 116 | extern VOID 117 | UNC_COMMON_Read_Counts ( 118 | PVOID param, 119 | U32 id 120 | ); 121 | 122 | 123 | /************************************************************/ 124 | /* 125 | * UNC common PCI based API 126 | * 127 | ************************************************************/ 128 | 129 | extern VOID 130 | UNC_COMMON_PCI_Write_PMU ( 131 | PVOID param, 132 | U32 ubox_did, 133 | U32 control_msr, 134 | U32 ctl_val, 135 | U32 pci_dev_index, 136 | DEVICE_CALLBACK callback 137 | ); 138 | 139 | extern VOID 140 | UNC_COMMON_PCI_Enable_PMU( 141 | PVOID param, 142 | U32 control_msr, 143 | U32 enable_val, 144 | U32 disable_val, 145 | DEVICE_CALLBACK callback 146 | ); 147 | 148 | 149 | extern VOID 150 | UNC_COMMON_PCI_Disable_PMU( 151 | PVOID param, 152 | U32 control_msr, 153 | U32 enable_val, 154 | U32 disable_val, 155 | DEVICE_CALLBACK callback 156 | ); 157 | 158 | extern OS_STATUS 159 | UNC_COMMON_Add_Bus_Map( 160 | U32 uncore_did, 161 | U32 dev_node, 162 | U32 bus_no 163 | ); 164 | 165 | extern OS_STATUS 166 | UNC_COMMON_Init(void); 167 | 168 | extern VOID 169 | UNC_COMMON_Clean_Up(void); 170 | 171 | extern VOID 172 | UNC_COMMON_PCI_Trigger_Read ( 173 | U32 id 174 | ); 175 | 176 | extern VOID 177 | UNC_COMMON_PCI_Read_PMU_Data( 178 | PVOID param 179 | ); 180 | 181 | extern VOID 182 | UNC_COMMON_PCI_Scan_For_Uncore( 183 | PVOID param, 184 | U32 dev_info_node, 185 | DEVICE_CALLBACK callback 186 | ); 187 | 188 | extern VOID 189 | UNC_COMMON_Get_Platform_Topology( 190 | U32 dev_info_node 191 | ); 192 | 193 | /************************************************************/ 194 | /* 195 | * UNC common MSR based API 196 | * 197 | ************************************************************/ 198 | 199 | extern VOID 200 | UNC_COMMON_MSR_Write_PMU ( 201 | PVOID param, 202 | U32 control_msr, 203 | U64 control_val, 204 | U64 reset_val, 205 | DEVICE_CALLBACK callback 206 | ); 207 | 208 | extern VOID 209 | UNC_COMMON_MSR_Enable_PMU( 210 | PVOID param, 211 | U32 control_msr, 212 | U64 control_val, 213 | U64 unit_ctl_val, 214 | U64 pmon_ctl_val, 215 | DEVICE_CALLBACK callback 216 | ); 217 | 218 | 219 | extern VOID 220 | UNC_COMMON_MSR_Disable_PMU( 221 | PVOID param, 222 | U32 control_msr, 223 | U64 unit_ctl_val, 224 | U64 pmon_ctl_val, 225 | DEVICE_CALLBACK callback 226 | ); 227 | 228 | extern VOID 229 | UNC_COMMON_MSR_Trigger_Read ( 230 | U32 id 231 | ); 232 | 233 | extern VOID 234 | UNC_COMMON_MSR_Read_PMU_Data( 235 | PVOID param 236 | ); 237 | 238 | extern VOID 239 | UNC_COMMON_MSR_Clean_Up( 240 | PVOID param 241 | ); 242 | 243 | 244 | #endif 245 | 246 | -------------------------------------------------------------------------------- /agentdk/sepagent_parser.c: -------------------------------------------------------------------------------- 1 | /**** 2 | Copyright (C) 2019-2020 Intel Corporation. All Rights Reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | 22 | 23 | 24 | 25 | 26 | 27 | ****/ 28 | 29 | #include "lwpmudrv_defines.h" 30 | #include "lwpmudrv_version.h" 31 | #include "lwpmudrv_types.h" 32 | #include "rise_errors.h" 33 | #include "lwpmudrv_ecb.h" 34 | #include "lwpmudrv_ioctl.h" 35 | #include "lwpmudrv_struct.h" 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #include "sepagent_parser.h" 42 | #include "log.h" 43 | 44 | DRV_BOOL verbose = FALSE; 45 | extern int sepagent_Print_Version(); 46 | 47 | // Macros to parse command line args 48 | #define IS_OPTION(token,str1) (strcmp(token, str1) == 0) 49 | #define IS_EITHER_OPTION(token,str1,str2) (strcmp(token, str1) == 0 || \ 50 | strcmp(token, str2) == 0) 51 | #define CHECK_END_OF_OPTION_AND_EXIT(a,b,c) \ 52 | if ((a) == (b)) { fprintf(stderr, (c)); return VT_SEP_OPTIONS_ERROR; } 53 | 54 | #define NUM_FIELDS_RUN_INFO 1 55 | static U32 is_dup_run_info[NUM_FIELDS_RUN_INFO]; 56 | /******************************************* 57 | / is_dup_run_info: what each index represents 58 | / [0] transfer mode 59 | *******************************************/ 60 | 61 | /* ------------------------------------------------------------------------- */ 62 | /*! 63 | * @fn void sep_parser_Str_Lower (char *token) 64 | * 65 | * @brief convert all characters in string to lower case 66 | * 67 | * @param token: string to process 68 | * 69 | * @return NONE 70 | * 71 | * Special Notes: 72 | * 73 | * ------------------------------------------------------------------------- */ 74 | static void 75 | sep_parser_Str_Lower ( 76 | char *token 77 | ) 78 | { 79 | U32 i = 0; 80 | while (token[i] != '\0') { 81 | token[i] = (char)tolower(token[i]); 82 | i++; 83 | } 84 | return; 85 | } 86 | 87 | /* ------------------------------------------------------------------------- */ 88 | /*! 89 | * @fn void sepagent_Print_help (void) 90 | * 91 | * @brief Print the usage messsage 92 | * 93 | * @param NONE 94 | * 95 | * @return NONE 96 | * 97 | * Special Notes: 98 | * Prints out detailed usage message. 99 | */ 100 | void SEPAGENT_Print_Help( 101 | void 102 | ) 103 | { 104 | fprintf(stdout, "Usage:\n"); 105 | fprintf(stdout, "\tsepagent [Options]\n"); 106 | fprintf(stdout, "Options:\n"); 107 | fprintf(stdout, "\t-start \t\t\t Start the collection\n"); 108 | fprintf(stdout, "\t [-tm \t Specify type of transfer [IMMEDIATE_TRANSFER/DELAYED_TRANSFER]}\n"); 109 | fprintf(stdout, "\t-version \t\t Display sepagent version info\n"); 110 | fprintf(stdout, "\t-v \t Verbose mode \n"); 111 | } 112 | /* ------------------------------------------------------------------------- */ 113 | /*! 114 | * @fn U32 sep_parser_tarnsfer_mode (INOUT U32 *i, 115 | * IN const U32 num_args, 116 | * IN STCHAR *options_arr[], 117 | * OUT U32 *data_transfer_mode 118 | * ) 119 | * @brief helper function used by parser to parse transfer mode 120 | * 121 | * @param IN i: index into options_arr 122 | * @param IN num_args: size of options_arr 123 | * @param IN options_arr: character array filled out with options 124 | * @param OUT data_transfer_mode: transfer mode info is filled into this variable 125 | * 126 | * @return VT_SUCCESS on success, otherwise on failure 127 | * 128 | * Special Notes: 129 | * 130 | * ------------------------------------------------------------------------- */ 131 | static int 132 | sep_parser_transfer_mode ( 133 | int *i, 134 | int num_args, 135 | char *options_arr[], 136 | int *data_transfer_mode 137 | ) 138 | { 139 | char *token; 140 | (*i)++; 141 | CHECK_END_OF_OPTION_AND_EXIT(*i, num_args, "Error: Invalid transfer mode value!\n"); 142 | token = options_arr[*i]; 143 | if (token[0] == '-') { 144 | fprintf (stderr, "Error: invalid transfer mode value!\n"); 145 | return VT_SEP_OPTIONS_ERROR; 146 | } 147 | 148 | if (is_dup_run_info[0] == 1) { 149 | fprintf(stderr, "\nWarning: duplicate values for transfer mode are given!"); 150 | } 151 | else { 152 | if (strcmp(token, "DELAYED_TRANSFER") == 0) { 153 | *data_transfer_mode = DELAYED_TRANSFER; 154 | } 155 | else if (strcmp(token, "IMMEDIATE_TRANSFER") == 0) { 156 | *data_transfer_mode = IMMEDIATE_TRANSFER; 157 | } 158 | else { 159 | fprintf (stderr, "Error: invalid transfer mode value!\n"); 160 | return VT_SEP_OPTIONS_ERROR; 161 | } 162 | is_dup_run_info[0] = 1; 163 | } 164 | return VT_SUCCESS; 165 | } 166 | 167 | 168 | /* ------------------------------------------------------------------------- */ 169 | /*! 170 | * @fn int sepagent_Parser 171 | * 172 | * @brief Parse the command line arguments 173 | * 174 | * @param IN num_args - Number of arguments 175 | * @param IN my_argv[] - the args list 176 | * @param OUT *data_transfer_mode - data transfer mode 177 | * 178 | * @return NONE 179 | * 180 | * Special Notes: None 181 | */ 182 | int SEPAGENT_Parser( 183 | int num_args, 184 | char *options_arr[], 185 | int *data_transfer_mode 186 | ) 187 | { 188 | int status = VT_SUCCESS; 189 | U32 i = 0; 190 | U32 print_version = FALSE; 191 | char *token; 192 | 193 | if (num_args > 1) { 194 | token = options_arr[1]; 195 | sep_parser_Str_Lower(token); 196 | if (IS_OPTION(token, "-start")) { 197 | for (i = 2; i < num_args; i++) { 198 | token = options_arr[i]; 199 | sep_parser_Str_Lower(token); 200 | if (IS_EITHER_OPTION(token, "-tm", "-transfer-mode")) { 201 | status = sep_parser_transfer_mode(&i, num_args, options_arr, data_transfer_mode); 202 | } 203 | else if (IS_OPTION(token, "-v")) { 204 | verbose = TRUE; 205 | } 206 | else { 207 | fprintf(stdout, "Error: Incorrect option provided!\n"); 208 | status = VT_SEP_OPTIONS_ERROR; 209 | } 210 | if (status != VT_SUCCESS) { 211 | return VT_SEP_OPTIONS_ERROR; 212 | } 213 | } 214 | } 215 | else if (IS_OPTION(token, "-version")) { 216 | status = sepagent_Print_Version(); 217 | if (status == VT_SUCCESS) { 218 | exit(0); 219 | } 220 | } 221 | else if (IS_OPTION(token, "-help")){ 222 | status = VT_SEP_OPTIONS_ERROR; 223 | } 224 | else { 225 | fprintf(stdout, "Error: Incorrect option provided!\n"); 226 | status = VT_SEP_OPTIONS_ERROR; 227 | } 228 | if (status != VT_SUCCESS) { 229 | return VT_SEP_OPTIONS_ERROR; 230 | } 231 | } 232 | else { 233 | return VT_SEP_OPTIONS_ERROR; 234 | } 235 | return VT_SUCCESS; 236 | } 237 | 238 | --------------------------------------------------------------------------------