Skip to contentSkip to conversation

Splitting up platform-specific calls

RFC PATCH Superseded Casey Bowman 5 participants 7 messages Feb 11, 2022 – Feb 15, 2022

Subsystems (2)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Splitting up platform-specific calls

In this RFC I would like to ask the community their thoughts on how we can best handle splitting architecture-specific calls.

I would like to address the following:

1. How do we want to split architecture calls? Different object files per platform? Separate function calls within the same object file?

2. How do we address dummy functions? If we have a function call that is used for one or more platforms, but is not used in another, what should we do for this case?

I've given an example of splitting an architecture call in my patch with run_as_guest() being split into different implementations for x86 and arm64 in separate object files, sharing a single header.

Another suggestion from Michael ([email protected]) involved using a single object file, a single header, and splitting various functions calls via ifdefs in the header file.

I would appreciate any input on how we can avoid scaling issues when including multiple architectures and multiple functions (as the number of function calls will inevitably increase with more architectures).

v2: Revised to use kernel's platform-splitting scheme.

Casey Bowman (1):
i915/drm: Split out x86 and arm64 functionality

 drivers/gpu/drm/i915/Makefile                         |  3 +++
 drivers/gpu/drm/i915/i915_drv.h                       |  7 ++-----
 drivers/gpu/drm/i915/platforms/Makefile               |  8 ++++++++
 .../arm64/include/platform/i915_hypervisor.h          | 11 +++++++++++
 .../platforms/x86/include/platform/i915_hypervisor.h  |  9 +++++++++
 5 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/platforms/Makefile
 create mode 100644 drivers/gpu/drm/i915/platforms/arm64/include/platform/i915_hypervisor.h
 create mode 100644 drivers/gpu/drm/i915/platforms/x86/include/platform/i915_hypervisor.h
Signature · 1 line
2.25.1
#1 lore raw

RFC PATCH v2 1/1 i915/drm: Split out x86 and arm64 functionality

Some x86 checks are unnecessary on arm64 systems, so they are being split out to avoid being used.

We are starting the split with run_as_guest(), which has an x86-specific usage, while on arm64, we aren't using it.

The split reflects the way the kernel currently handles platform-specific libraries, but these calls are localized to i915.

---
 drivers/gpu/drm/i915/Makefile                         |  3 +++
 drivers/gpu/drm/i915/i915_drv.h                       |  7 ++-----
 drivers/gpu/drm/i915/platforms/Makefile               |  8 ++++++++
 .../arm64/include/platform/i915_hypervisor.h          | 11 +++++++++++
 .../platforms/x86/include/platform/i915_hypervisor.h  |  9 +++++++++
 5 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/platforms/Makefile
 create mode 100644 drivers/gpu/drm/i915/platforms/arm64/include/platform/i915_hypervisor.h
 create mode 100644 drivers/gpu/drm/i915/platforms/x86/include/platform/i915_hypervisor.h
drivers/gpu/drm/i915/Makefile +3 -0
index 16cab8db012a..f69ed0c10e80 100644
@@ -29,6 +29,9 @@ subdir-ccflags-y += -I$(srctree)/$(src)
 
 # Please keep these build lists sorted!
 
+# arch support
+include $(src)/platforms/Makefile
+
 # core driver code
 i915-y += i915_driver.o \
 	  i915_config.o \
drivers/gpu/drm/i915/i915_drv.h +2 -5
index 78fa3340101b..ba2cfb4d9830 100644
@@ -87,6 +87,8 @@
 #include "gt/intel_workarounds.h"
 #include "gt/uc/intel_uc.h"
 
+#include "platform/i915_hypervisor.h"
+
 #include "intel_device_info.h"
 #include "intel_memory_region.h"
 #include "intel_pch.h"
@@ -1498,11 +1500,6 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915,
 #define INTEL_DISPLAY_ENABLED(dev_priv) \
 	(drm_WARN_ON(&(dev_priv)->drm, !HAS_DISPLAY(dev_priv)), !(dev_priv)->params.disable_display)
 
-static inline bool run_as_guest(void)
-{
-	return !hypervisor_is_type(X86_HYPER_NATIVE);
-}
-
 #define HAS_D12_PLANE_MINIMIZATION(dev_priv) (IS_ROCKETLAKE(dev_priv) || \
 					      IS_ALDERLAKE_S(dev_priv))
 
drivers/gpu/drm/i915/platforms/Makefile new file +8 -0
new file mode 100644
index 000000000000..03250b5704ea
@@ -0,0 +1,8 @@
+ifdef CONFIG_X86
+ccflags-y += -I $(srctree)/$(src)/platforms/x86/include/
+endif
+
+ifdef CONFIG_ARM64
+ccflags-y += -I $(srctree)/$(src)/platforms/arm64/include/
+endif
+
drivers/gpu/drm/i915/platforms/arm64/include/platform/i915_hypervisor.h new file +11 -0
new file mode 100644
index 000000000000..cd9050711dce
@@ -0,0 +1,11 @@
+#ifndef _I915_HYPERVISOR_
+#define _I915_HYPERVISOR_
+
+
+/* Not supported for arm64, so we return  */
+static inline bool run_as_guest(void)
+{
+	return false;
+}
+
+#endif
drivers/gpu/drm/i915/platforms/x86/include/platform/i915_hypervisor.h new file +9 -0
new file mode 100644
index 000000000000..5eab54f5e09f
@@ -0,0 +1,9 @@
+#ifndef _I915_HYPERVISOR_
+#define _I915_HYPERVISOR_
+
+static inline bool run_as_guest(void)
+{
+	return !hypervisor_is_type(X86_HYPER_NATIVE);
+}
+
+#endif
Signature · 1 line
2.25.1
#2 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for Splitting up platform-specific calls (rev2)

In reply to Casey Bowman
== Series Details ==

== Series Details ==

Series: Splitting up platform-specific calls (rev2)
URL : https://patchwork.freedesktop.org/series/99126/
State : failure

== Summary ==

Applying: i915/drm: Split out x86 and arm64 functionality .git/rebase-apply/patch:64: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/Makefile
M drivers/gpu/drm/i915/i915_drv.h
Falling back to patching base and 3-way merge... Auto-merging drivers/gpu/drm/i915/i915_drv.h
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/i915_drv.h Auto-merging drivers/gpu/drm/i915/Makefile
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 i915/drm: Split out x86 and arm64 functionality When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

#3 lore raw
In reply to Casey Bowman
Quoted 22 lines · Casey Bowman

In this RFC I would like to ask the community their thoughts on how we can best handle splitting architecture-specific calls.

I would like to address the following:

1. How do we want to split architecture calls? Different object files per platform? Separate function calls within the same object file?

2. How do we address dummy functions? If we have a function call that is used for one or more platforms, but is not used in another, what should we do for this case?

I've given an example of splitting an architecture call in my patch with run_as_guest() being split into different implementations for x86 and arm64 in separate object files, sharing a single header.

Another suggestion from Michael ([email protected]) involved using a single object file, a single header, and splitting various functions calls via ifdefs in the header file.

Quoted 5 lines

I would appreciate any input on how we can avoid scaling issues when including multiple architectures and multiple functions (as the number of function calls will inevitably increase with more architectures).

v2: Revised to use kernel's platform-splitting scheme.

I think this is overengineering.

Just add different implementations of the functions per architecture next to where they are now, like I suggested before.

If we need to split them better later, it'll be a trivial undertaking, and we'll be in a better position to do it because we'll know how many functions there'll be and where they are and what they do.

Adding a bunch of overhead from the start seems like the wrong thing to do.

BR,
Jani.

Quoted 13 lines

Casey Bowman (1):
i915/drm: Split out x86 and arm64 functionality

 drivers/gpu/drm/i915/Makefile                         |  3 +++
 drivers/gpu/drm/i915/i915_drv.h                       |  7 ++-----
 drivers/gpu/drm/i915/platforms/Makefile               |  8 ++++++++
 .../arm64/include/platform/i915_hypervisor.h          | 11 +++++++++++
 .../platforms/x86/include/platform/i915_hypervisor.h  |  9 +++++++++
 5 files changed, 33 insertions(+), 5 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/platforms/Makefile
 create mode 100644 drivers/gpu/drm/i915/platforms/arm64/include/platform/i915_hypervisor.h
 create mode 100644 drivers/gpu/drm/i915/platforms/x86/include/platform/i915_hypervisor.h
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
#4 lore raw
Quoted 34 lines · Jani Nikula
Quoted 22 lines · Casey Bowman

In this RFC I would like to ask the community their thoughts on how we can best handle splitting architecture-specific calls.

I would like to address the following:

1. How do we want to split architecture calls? Different object files per platform? Separate function calls within the same object file?

2. How do we address dummy functions? If we have a function call that is used for one or more platforms, but is not used in another, what should we do for this case?

I've given an example of splitting an architecture call in my patch with run_as_guest() being split into different implementations for x86 and arm64 in separate object files, sharing a single header.

Another suggestion from Michael ([email protected]) involved using a single object file, a single header, and splitting various functions calls via ifdefs in the header file.

Quoted 5 lines

I would appreciate any input on how we can avoid scaling issues when including multiple architectures and multiple functions (as the number of function calls will inevitably increase with more architectures).

v2: Revised to use kernel's platform-splitting scheme.

I think this is overengineering.

Just add different implementations of the functions per architecture next to where they are now, like I suggested before.

Quoted 6 lines

If we need to split them better later, it'll be a trivial undertaking, and we'll be in a better position to do it because we'll know how many functions there'll be and where they are and what they do.

Adding a bunch of overhead from the start seems like the wrong thing to do.

I don't see it adds real complexity, which would normally be associated with over-engineering. As a benefit I see it helping with driving the clean re-design (during the porting effort) in a way that it will be easy to spot is something is overly hacky, split on the wrong level, or incorrectly placed.

And it moves run_as_guest outside of intel_vtd.[hc] which IMO shows immediate benefit, since it has nothing to do with intel_vtd.

I suggested to add clflush as well, since I think going for drm_flush_virt_range everywhere is a bit lazy given how it is a clear regression for older platforms.

But after that I indeed don't have a crystal ball to show me how many more appropriate low-level primitives would be to use the pattern.

So my vote would be to go with it, although the main thing is probably to solve the conflicting asks and let guys focus on the port. Put it to voting then? :)

Regards,

Tvrtko

#5 lore raw
Quoted 45 lines · Tvrtko Ursulin
Quoted 34 lines · Jani Nikula
Quoted 22 lines · Casey Bowman

In this RFC I would like to ask the community their thoughts on how we can best handle splitting architecture-specific calls.

I would like to address the following:

1. How do we want to split architecture calls? Different object files per platform? Separate function calls within the same object file?

2. How do we address dummy functions? If we have a function call that is used for one or more platforms, but is not used in another, what should we do for this case?

I've given an example of splitting an architecture call in my patch with run_as_guest() being split into different implementations for x86 and arm64 in separate object files, sharing a single header.

Another suggestion from Michael ([email protected]) involved using a single object file, a single header, and splitting various functions calls via ifdefs in the header file.

Quoted 5 lines

I would appreciate any input on how we can avoid scaling issues when including multiple architectures and multiple functions (as the number of function calls will inevitably increase with more architectures).

v2: Revised to use kernel's platform-splitting scheme.

I think this is overengineering.

Just add different implementations of the functions per architecture next to where they are now, like I suggested before.

Quoted 6 lines

If we need to split them better later, it'll be a trivial undertaking, and we'll be in a better position to do it because we'll know how many functions there'll be and where they are and what they do.

Adding a bunch of overhead from the start seems like the wrong thing to do.

I don't see it adds real complexity, which would normally be associated with over-engineering. As a benefit I see it helping with driving the clean re-design (during the porting effort) in a way that it will be easy to spot is something is overly hacky, split on the wrong level, or incorrectly placed.

Quoted 8 lines

And it moves run_as_guest outside of intel_vtd.[hc] which IMO shows immediate benefit, since it has nothing to do with intel_vtd.

I suggested to add clflush as well, since I think going for drm_flush_virt_range everywhere is a bit lazy given how it is a clear regression for older platforms.

But after that I indeed don't have a crystal ball to show me how many more appropriate low-level primitives would be to use the pattern.

So my vote would be to go with it, although the main thing is probably to solve the conflicting asks and let guys focus on the port. Put it to voting then? :)

If we can get someone else to weigh in here to break the tie, that'd be helpful :)

Regards,
Casey

#6 lore raw
Quoted 49 lines · Casey Bowman
Quoted 47 lines · Tvrtko Ursulin
Quoted 34 lines · Jani Nikula
Quoted 22 lines · Casey Bowman

In this RFC I would like to ask the community their thoughts on how we can best handle splitting architecture-specific calls.

I would like to address the following:

1. How do we want to split architecture calls? Different object files per platform? Separate function calls within the same object file?

2. How do we address dummy functions? If we have a function call that is used for one or more platforms, but is not used in another, what should we do for this case?

I've given an example of splitting an architecture call in my patch with run_as_guest() being split into different implementations for x86 and arm64 in separate object files, sharing a single header.

Another suggestion from Michael ([email protected]) involved using a single object file, a single header, and splitting various functions calls via ifdefs in the header file.

Quoted 5 lines

I would appreciate any input on how we can avoid scaling issues when including multiple architectures and multiple functions (as the number of function calls will inevitably increase with more architectures).

v2: Revised to use kernel's platform-splitting scheme.

I think this is overengineering.

Just add different implementations of the functions per architecture next to where they are now, like I suggested before.

Quoted 6 lines

If we need to split them better later, it'll be a trivial undertaking, and we'll be in a better position to do it because we'll know how many functions there'll be and where they are and what they do.

Adding a bunch of overhead from the start seems like the wrong thing to do.

I don't see it adds real complexity, which would normally be associated with over-engineering. As a benefit I see it helping with driving the clean re-design (during the porting effort) in a way that it will be easy to spot is something is overly hacky, split on the wrong level, or incorrectly placed.

And it moves run_as_guest outside of intel_vtd.[hc] which IMO shows immediate benefit, since it has nothing to do with intel_vtd.

Quoted 7 lines
Quoted 6 lines

I suggested to add clflush as well, since I think going for drm_flush_virt_range everywhere is a bit lazy given how it is a clear regression for older platforms.

But after that I indeed don't have a crystal ball to show me how many more appropriate low-level primitives would be to use the pattern.

So my vote would be to go with it, although the main thing is probably to solve the conflicting asks and let guys focus on the port. Put it to voting then? :)

If we can get someone else to weigh in here to break the tie, that'd be helpful :)

I don't like much the split with platforms because a) I don't think we have too many users to deserve that, b) if we do have something that is common and should be abstracted in that way, it should probably be outside of i915: find somewhere in the kernel that is the proper place to add that and c) usually we will have "do one thing for x86, do another for all the rest" - and the split per platform forces us to add an implementation for each platform (or add a generic/ to account for the absence of something). There will usually be one (x86) that will be very different than the rest.

So my vote is to go with Jani's proposal.

Lucas De Marchi

Quoted 4 lines

Regards,
Casey