Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 103b76ee authored by Chris Wilson's avatar Chris Wilson
Browse files

drm/i915: Use i915_global_register()



Rather than manually add every new global into each hook, use
i915_global_register() function and keep a list of registered globals to
invoke instead.

However, I haven't found a way for random drivers to add an .init table
to avoid having to manually add ourselves to i915_globals_init() each
time.

Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20190305213830.18094-1-chris@chris-wilson.co.uk


Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
parent d846325a
Loading
Loading
Loading
Loading
+18 −10
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@

#include "i915_drv.h"
#include "i915_active.h"
#include "i915_globals.h"

#define BKL(ref) (&(ref)->i915->drm.struct_mutex)

@@ -17,6 +18,7 @@
 * nodes from a local slab cache to hopefully reduce the fragmentation.
 */
static struct i915_global_active {
	struct i915_global base;
	struct kmem_cache *slab_cache;
} global;

@@ -285,21 +287,27 @@ void i915_active_retire_noop(struct i915_active_request *active,
#include "selftests/i915_active.c"
#endif

int __init i915_global_active_init(void)
static void i915_global_active_shrink(void)
{
	global.slab_cache = KMEM_CACHE(active_node, SLAB_HWCACHE_ALIGN);
	if (!global.slab_cache)
		return -ENOMEM;

	return 0;
	kmem_cache_shrink(global.slab_cache);
}

void i915_global_active_shrink(void)
static void i915_global_active_exit(void)
{
	kmem_cache_shrink(global.slab_cache);
	kmem_cache_destroy(global.slab_cache);
}

void i915_global_active_exit(void)
static struct i915_global_active global = { {
	.shrink = i915_global_active_shrink,
	.exit = i915_global_active_exit,
} };

int __init i915_global_active_init(void)
{
	kmem_cache_destroy(global.slab_cache);
	global.slab_cache = KMEM_CACHE(active_node, SLAB_HWCACHE_ALIGN);
	if (!global.slab_cache)
		return -ENOMEM;

	i915_global_register(&global.base);
	return 0;
}
+0 −4
Original line number Diff line number Diff line
@@ -419,8 +419,4 @@ void i915_active_fini(struct i915_active *ref);
static inline void i915_active_fini(struct i915_active *ref) { }
#endif

int i915_global_active_init(void);
void i915_global_active_shrink(void);
void i915_global_active_exit(void);

#endif /* _I915_ACTIVE_H_ */
+18 −10
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@
#include <linux/log2.h>
#include <drm/i915_drm.h>
#include "i915_drv.h"
#include "i915_globals.h"
#include "i915_trace.h"
#include "intel_lrc_reg.h"
#include "intel_workarounds.h"
@@ -95,6 +96,7 @@
#define ALL_L3_SLICES(dev) (1 << NUM_L3_SLICES(dev)) - 1

static struct i915_global_context {
	struct i915_global base;
	struct kmem_cache *slab_luts;
} global;

@@ -1423,21 +1425,27 @@ int __i915_gem_context_pin_hw_id(struct i915_gem_context *ctx)
#include "selftests/i915_gem_context.c"
#endif

int __init i915_global_context_init(void)
static void i915_global_context_shrink(void)
{
	global.slab_luts = KMEM_CACHE(i915_lut_handle, 0);
	if (!global.slab_luts)
		return -ENOMEM;

	return 0;
	kmem_cache_shrink(global.slab_luts);
}

void i915_global_context_shrink(void)
static void i915_global_context_exit(void)
{
	kmem_cache_shrink(global.slab_luts);
	kmem_cache_destroy(global.slab_luts);
}

void i915_global_context_exit(void)
static struct i915_global_context global = { {
	.shrink = i915_global_context_shrink,
	.exit = i915_global_context_exit,
} };

int __init i915_global_context_init(void)
{
	kmem_cache_destroy(global.slab_luts);
	global.slab_luts = KMEM_CACHE(i915_lut_handle, 0);
	if (!global.slab_luts)
		return -ENOMEM;

	i915_global_register(&global.base);
	return 0;
}
+0 −4
Original line number Diff line number Diff line
@@ -411,8 +411,4 @@ void intel_context_init(struct intel_context *ce,
struct i915_lut_handle *i915_lut_handle_alloc(void);
void i915_lut_handle_free(struct i915_lut_handle *lut);

int i915_global_context_init(void);
void i915_global_context_shrink(void);
void i915_global_context_exit(void);

#endif /* !__I915_GEM_CONTEXT_H__ */
+18 −10
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@

#include "i915_drv.h"
#include "i915_gem_object.h"
#include "i915_globals.h"

static struct i915_global_object {
	struct i915_global base;
	struct kmem_cache *slab_objects;
} global;

@@ -61,6 +63,21 @@ void i915_gem_object_set_cache_coherency(struct drm_i915_gem_object *obj,
		!(obj->cache_coherent & I915_BO_CACHE_COHERENT_FOR_WRITE);
}

static void i915_global_objects_shrink(void)
{
	kmem_cache_shrink(global.slab_objects);
}

static void i915_global_objects_exit(void)
{
	kmem_cache_destroy(global.slab_objects);
}

static struct i915_global_object global = { {
	.shrink = i915_global_objects_shrink,
	.exit = i915_global_objects_exit,
} };

int __init i915_global_objects_init(void)
{
	global.slab_objects =
@@ -68,15 +85,6 @@ int __init i915_global_objects_init(void)
	if (!global.slab_objects)
		return -ENOMEM;

	i915_global_register(&global.base);
	return 0;
}

void i915_global_objects_shrink(void)
{
	kmem_cache_shrink(global.slab_objects);
}

void i915_global_objects_exit(void)
{
	kmem_cache_destroy(global.slab_objects);
}
Loading