Skip to content

Commit

Permalink
Merge branch 'main' into user/anusa/issue_3699
Browse files Browse the repository at this point in the history
  • Loading branch information
saxena-anurag authored Sep 6, 2024
2 parents 24381d1 + c73a086 commit 4c4937b
Show file tree
Hide file tree
Showing 23 changed files with 2,578 additions and 769 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/netperf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ jobs:
gh run download $run_id --dir netperf --pattern ebpf* --repo microsoft/netperf
- name: upload_results_azure_2022_x64
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: Test-Logs-netperf_azure_2022_x64
path: netperf/ebpf_azure_2022_x64/ebpf.csv

- name: upload_results_lab_2022_x64
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: Test-Logs-netperf_lab_2022_x64
path: netperf/ebpf_lab_2022_x64/ebpf.csv
2 changes: 1 addition & 1 deletion .github/workflows/ossar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ jobs:

- name: Upload results to Security tab
if: steps.skip_check.outputs.should_skip != 'true'
uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93
with:
sarif_file: ${{ steps.ossar.outputs.sarifFile }}
14 changes: 7 additions & 7 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
- name: Initialize CodeQL
if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true'
uses: github/codeql-action/init@2c779ab0d087cd7fe7b826087247c2c81f27bfa6
uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93
with:
languages: 'cpp'

Expand Down Expand Up @@ -229,15 +229,15 @@ jobs:
- name: Upload Build Output
if: always() && (steps.skip_check.outputs.should_skip != 'true') && (inputs.build_artifact != 'none')
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: ${{inputs.build_artifact}}-${{matrix.configurations}}
path: ${{github.workspace}}/build-${{ matrix.configurations }}.zip
retention-days: 5

- name: Upload the MSI package
if: inputs.build_msi == true
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: ebpf-for-windows - MSI installer (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}})
path: ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/ebpf-for-windows.msi
Expand All @@ -249,7 +249,7 @@ jobs:

- name: Upload the NuGet package
if: inputs.build_nuget == true && matrix.configurations == 'Release' && steps.skip_check.outputs.should_skip != 'true'
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: ebpf-for-windows - NuGet package (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}})
path: ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/eBPF-for-Windows.*.nupkg
Expand All @@ -261,7 +261,7 @@ jobs:

- name: Upload the NuGet Redist package
if: inputs.build_nuget == true && (matrix.configurations == 'Release' || matrix.configurations == 'NativeOnlyRelease') && steps.skip_check.outputs.should_skip != 'true'
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: ebpf-for-windows - NuGet Redist package (${{inputs.build_artifact}}_${{env.BUILD_CONFIGURATION}})
path: ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/eBPF-for-Windows-Redist.*.nupkg
Expand All @@ -277,7 +277,7 @@ jobs:
- name: Upload any crash dumps
# Upload crash dumps even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_dumps.outputs.files_exists == 'true')
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
id: upload_crash_dumps
with:
name: Crash-Dumps-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
Expand All @@ -286,4 +286,4 @@ jobs:

- name: Perform CodeQL Analysis
if: inputs.build_codeql == true && steps.skip_check.outputs.should_skip != 'true'
uses: github/codeql-action/analyze@2c779ab0d087cd7fe7b826087247c2c81f27bfa6
uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93
6 changes: 3 additions & 3 deletions .github/workflows/reusable-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ jobs:
- name: Upload any crash dumps
# Upload crash dumps even if the workflow failed.
if: always() && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_dumps.outputs.files_exists == 'true') && (inputs.gather_dumps == true)
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
id: upload_crash_dumps
with:
name: Crash-Dumps-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
Expand All @@ -423,7 +423,7 @@ jobs:
# Upload test logs even if the workflow failed.
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_logs.outputs.files_exists == 'true')
id: upload_logs
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
continue-on-error: true
with:
name: Test-Logs-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
Expand All @@ -443,7 +443,7 @@ jobs:
if: (success() || failure()) && (steps.skip_check.outputs.should_skip != 'true') && (steps.check_artifacts.outputs.files_exists == 'true')
id: upload_artifacts
continue-on-error: true
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: Artifacts-${{env.NAME}}-${{env.BUILD_PLATFORM}}-${{env.BUILD_CONFIGURATION}}
path: ${{github.workspace}}\${{env.BUILD_PLATFORM}}\${{env.BUILD_CONFIGURATION}}\Artifacts
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# Upload the results as artifacts (optional).
- name: "Upload artifact"
if: github.ref_name == 'main'
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: SARIF file
path: results.sarif
Expand All @@ -76,6 +76,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
if: github.ref_name == 'main'
uses: github/codeql-action/upload-sarif@2c779ab0d087cd7fe7b826087247c2c81f27bfa6
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion .github/workflows/upload-perf-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
# Grab the output from the results directory and upload it as an artifact to debug failures.
- name: Upload data as artifacts for debugging
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: Test-Results-${{inputs.result_artifact}}
path: ${{github.workspace}}/results
Expand Down
2 changes: 1 addition & 1 deletion external/ebpf-verifier
50 changes: 42 additions & 8 deletions libs/runtime/ebpf_hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "ebpf_hash_table.h"
#include "ebpf_random.h"

#include <nmmintrin.h>

// Buckets contain an array of pointers to value and keys.
// Buckets are immutable once inserted in to the hash-table and replaced when
// modified.
Expand Down Expand Up @@ -154,6 +156,33 @@ _ebpf_murmur3_32(_In_reads_((length_in_bits + 7) / 8) const uint8_t* key, size_t
return hash;
}

static unsigned long
_ebpf_compute_crc32(_In_reads_(length_in_bytes) const uint8_t* key, size_t length_in_bytes, uint32_t seed)
{
// First process 8 bytes at a time.
uint32_t crc = seed;
uint8_t* start = (uint8_t*)key;
uint8_t* end = start + length_in_bytes;

while ((end - start) >= 8) {
crc = (uint32_t)_mm_crc32_u64(crc, *(uint64_t*)start);
start += 8;
}

// Process 4 bytes at a time.
while ((end - start) >= 4) {
crc = _mm_crc32_u32(crc, *(uint32_t*)start);
start += 4;
}

// Process remaining bytes.
while ((end - start) > 0) {
crc = _mm_crc32_u8(crc, *start);
start++;
}
return crc;
}

/**
* @brief Compare keys assuming they are integers.
*
Expand Down Expand Up @@ -279,16 +308,18 @@ _ebpf_hash_table_compare(_In_ const ebpf_hash_table_t* hash_table, _In_ const ui
static uint32_t
_ebpf_hash_table_compute_bucket_index(_In_ const ebpf_hash_table_t* hash_table, _In_ const uint8_t* key)
{
size_t length;
const uint8_t* data;
if (hash_table->extract) {
hash_table->extract(key, &data, &length);
if (!hash_table->extract) {
if (ebpf_processor_supports_sse42) {
return _ebpf_compute_crc32(key, hash_table->key_size, hash_table->seed) & hash_table->bucket_count_mask;
} else {
return _ebpf_murmur3_32(key, hash_table->key_size * 8, hash_table->seed) & hash_table->bucket_count_mask;
}
} else {
length = hash_table->key_size * 8;
data = key;
uint8_t* data;
size_t length;
hash_table->extract(key, &data, &length);
return _ebpf_murmur3_32(data, length, hash_table->seed) & hash_table->bucket_count_mask;
}
uint32_t hash_value = _ebpf_murmur3_32(data, length, hash_table->seed);
return hash_value & hash_table->bucket_count_mask;
}

/**
Expand Down Expand Up @@ -758,6 +789,9 @@ ebpf_hash_table_find(_In_ const ebpf_hash_table_t* hash_table, _In_ const uint8_
goto Done;
}

// Prefetch the data on the assumption that it will be used by the caller soon.
_mm_prefetch((const char*)data, _MM_HINT_T0);

*value = data;
if (hash_table->notification_callback) {
hash_table->notification_callback(
Expand Down
11 changes: 11 additions & 0 deletions libs/runtime/ebpf_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ static uint32_t _ebpf_platform_maximum_processor_count = 0;

static bool _ebpf_platform_is_cxplat_initialized = false;

bool ebpf_processor_supports_sse42 = true;

_Ret_range_(>, 0) uint32_t ebpf_get_cpu_count() { return _ebpf_platform_maximum_processor_count; }

void
Expand Down Expand Up @@ -513,12 +515,21 @@ ebpf_allocate_preemptible_work_item(
return ebpf_result_from_cxplat_status(status);
}

#define CPU_INFO_PROCESSOR_INFO_FUNCTION 1
#define CPU_INFO_SSE42_BYTE_OFFSET 2
#define CPU_INFO_SSE32_BIT_OFFSET 20

_Must_inspect_result_ ebpf_result_t
ebpf_platform_initiate()
{
ebpf_result_t result = ebpf_result_from_cxplat_status(cxplat_initialize());
_ebpf_platform_is_cxplat_initialized = (result == EBPF_SUCCESS);
ebpf_initialize_cpu_count();
// Check if processor supports SSE4.2
int cpu_info[4] = {0};
__cpuid(cpu_info, CPU_INFO_PROCESSOR_INFO_FUNCTION);
ebpf_processor_supports_sse42 = (cpu_info[CPU_INFO_SSE42_BYTE_OFFSET] & (1 << CPU_INFO_SSE32_BIT_OFFSET)) != 0;

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions libs/runtime/ebpf_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ extern "C"
_Ret_notnull_ DEVICE_OBJECT*
ebpf_driver_get_device_object();

extern bool ebpf_processor_supports_sse42;

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 4c4937b

Please sign in to comment.