Skip to content

Conversation

ExceptionalHandler
Copy link
Contributor

@ExceptionalHandler ExceptionalHandler commented Mar 10, 2025

Description

This change attempts to port ktime, constants and pkg/sensors package to Windows following changes made via #3445. This is the strategy

1. Windows specific .go files are added in this PR for ktime, constants and sensors package
2. We bring back `pkg/sensors/unloader/unloader.go` , `pkg/sensors/tracing/policyhandler.go` and `pkg/sensors/sensors.go` and separate only platform specific code in these listings. 
3. Lot of code, we know not used on Windows is removed. Examples include LSM, multi kprobes etc. 
4. Functions required to build on Windows, but are not supported return "not supported on windows" error

Caveats

This is a change to prepare for Windows build and port. This does not compile on Windows yet, as more changes to dependent packages will be added in subsequent PR.

Changelog

Add windows implementation to ktime, constants and sensor packages. 

@ExceptionalHandler ExceptionalHandler requested a review from a team as a code owner March 10, 2025 21:58
@ExceptionalHandler ExceptionalHandler changed the title Windows build 2 Windows: Build tetragon on Windows (Part -2) Mar 10, 2025
@ExceptionalHandler ExceptionalHandler force-pushed the windows_build_2 branch 4 times, most recently from cafb9c1 to 5cf27cb Compare March 10, 2025 22:35
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Please find some comments bellow.

Generally, let's try to avoid code duplication as much as possible. If it's not possible, then let's at least document why.

@ExceptionalHandler ExceptionalHandler force-pushed the windows_build_2 branch 2 times, most recently from f905fc6 to 0cc7f7c Compare March 17, 2025 22:27
Copy link

netlify bot commented Mar 20, 2025

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit dcf79cc
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/67dc4105e3ac9a00086c941e
😎 Deploy Preview https://deploy-preview-3488--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

)

// isList checks if a value specifies a list, and if so it returns it (or nil if list does not exist)
func isList(val string, lists []v1alpha1.ListSpec) (bool, *v1alpha1.ListSpec) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? I feel that it can be either removed or use a common version for both windows/linux


func createLoaderEvents() error {

return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we return an error (e.g., not supported) here?

Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I misclicked and some text was not submitted in the review.
Adding it here.

It seems to me that there is a lot of code duplication between the linux and the windows version. For example, looking at load_windows.go and load_linux.go, there are 15 and 17 functions, respectively. Out of those only 3 seem to have differences. Can we just add all the common code in a load.go file?

$ git grep ^func pkg/sensors/load_windows.go | wc -l
15
$ git grep ^func pkg/sensors/load_linux.go | wc -l
17
$  diff -u pkg/sensors/load_linux.go pkg/sensors/load_windows.go | grep func
-func (s *Sensor) setMapPinPath(m *program.Map) {
-func (s *Sensor) loadMap(bpfDir string, m *program.Map) error {
 func mergeSensors(sensors []*Sensor) *Sensor {
 func observerMinReqs() (bool, error) {

@ExceptionalHandler
Copy link
Contributor Author

It seems to me that there is a lot of code duplication between the linux and the windows version. For example, looking at load_windows.go and load_linux.go, there are 15 and 17 functions, respectively. Out of those only 3 seem to have differences. Can we just add all the common code in a load.go file?

'load.go' is added in latest commit.

Copy link
Contributor

@olsajiri olsajiri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, left one minor comment, thanks

return nil
}

func observerLoadInstance(bpfDir string, load *program.Program, maps []*program.Map) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, linux version has some additional code (with unload for tracepoint),
but I think it can be removed (need to check) and we could move observerLoadInstance to load.go,
but I'll put this on my todo and submit that as follow up

@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, could you plz rename rename 'sensor' to 'sensors' in the path, so we'd have:

pkg/sensors/sensors_types_linux.go      
pkg/sensors/sensors_types_windows.go    

@olsajiri olsajiri added the release-note/minor This PR introduces a minor user-visible change label Mar 24, 2025
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nits.

LGTM, thanks!

Use Win32 API QueryPerformanceCounter to implement the ktime package on Windows.
monotonic version uses time package

Signed-off-by: Anadi Anadi <[email protected]>
Add constants_windows.go to allow access to constants to windows specific code.
Some windows constants are same as those defined in sys/unix package, their values are hardcoded.
Some windows constants are specific to Windows and are imported from sys/windows package

Signed-off-by: Anadi Anadi <[email protected]>
Add platform specific and platform common code in sensors/tracing package

Signed-off-by: Anadi Anadi <[email protected]>
In order to port sensor package on Windows, adding exec parser and loader / unloader for Windows
Tried to keep common functions between two OS in pkg/sensors/load.go.
The windows implementation of some functions in load_windows.go looks like Linux implementation but is different because of unavailability of some features on windows like bpffs and btf.
Also, the sensors.load() function in Windows is a work in progress and we might deprioritize code-reuse in favour of an ability to make future changes independently.

Signed-off-by: Anadi Anadi <[email protected]>
@ExceptionalHandler ExceptionalHandler merged commit b3dc538 into cilium:main Mar 26, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor This PR introduces a minor user-visible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants