[sysprof] governor: disable paranoid setting in governor source



commit 52e04cf34699c333a73ecd8ffe2abecb91831216
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 24 11:56:22 2021 -0800

    governor: disable paranoid setting in governor source
    
    This could be it's own source, but it's nice to have it in one place
    with our performance tooling.

 src/libsysprof/sysprof-governor-source.c | 62 ++++++++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/libsysprof/sysprof-governor-source.c b/src/libsysprof/sysprof-governor-source.c
index ca33f2d..ad99365 100644
--- a/src/libsysprof/sysprof-governor-source.c
+++ b/src/libsysprof/sysprof-governor-source.c
@@ -29,6 +29,7 @@ struct _SysprofGovernorSource
 {
   GObject parent_instance;
   gchar *old_governor;
+  int old_paranoid;
   guint disable_governor : 1;
 };
 
@@ -108,7 +109,7 @@ sysprof_governor_source_class_init (SysprofGovernorSourceClass *klass)
                           "Disable Governor",
                           TRUE,
                           (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
-  
+
   g_object_class_install_properties (object_class, N_PROPS, properties);
 }
 
@@ -176,6 +177,28 @@ sysprof_governor_source_deserialize (SysprofSource *source,
                                                 g_key_file_get_boolean (keyfile, group, "disable-governor", 
NULL));
 }
 
+static void
+disable_paranoid_cb (GObject      *object,
+                     GAsyncResult *result,
+                     gpointer      user_data)
+{
+  SysprofHelpers *helpers = (SysprofHelpers *)object;
+  g_autoptr(SysprofGovernorSource) self = user_data;
+  g_autoptr(GError) error = NULL;
+  int old_paranoid;
+
+  g_assert (SYSPROF_IS_HELPERS (helpers));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (SYSPROF_IS_GOVERNOR_SOURCE (self));
+
+  if (!sysprof_helpers_set_paranoid_finish (helpers, result, &old_paranoid, &error))
+    g_warning ("Failed to change perf_event_paranoid: %s", error->message);
+  else
+    self->old_paranoid = old_paranoid;
+
+  sysprof_source_emit_ready (SYSPROF_SOURCE (self));
+}
+
 static void
 disable_governor_cb (GObject      *object,
                      GAsyncResult *result,
@@ -195,7 +218,33 @@ disable_governor_cb (GObject      *object,
   else
     self->old_governor = g_steal_pointer (&old_governor);
 
-  sysprof_source_emit_ready (SYSPROF_SOURCE (self));
+  /* Now tweak paranoid setting */
+  sysprof_helpers_set_paranoid_async (helpers,
+                                      -1,
+                                      NULL,
+                                      disable_paranoid_cb,
+                                      g_steal_pointer (&self));
+}
+
+
+static void
+enable_paranoid_cb (GObject      *object,
+                    GAsyncResult *result,
+                    gpointer      user_data)
+{
+  SysprofHelpers *helpers = (SysprofHelpers *)object;
+  g_autoptr(SysprofGovernorSource) self = user_data;
+  g_autoptr(GError) error = NULL;
+  int old_governor;
+
+  g_assert (SYSPROF_IS_HELPERS (helpers));
+  g_assert (G_IS_ASYNC_RESULT (result));
+  g_assert (SYSPROF_IS_GOVERNOR_SOURCE (self));
+
+  if (!sysprof_helpers_set_paranoid_finish (helpers, result, &old_governor, &error))
+    g_warning ("Failed to change event_perf_paranoid: %s", error->message);
+
+  sysprof_source_emit_finished (SYSPROF_SOURCE (self));
 }
 
 static void
@@ -207,6 +256,7 @@ enable_governor_cb (GObject      *object,
   g_autoptr(SysprofGovernorSource) self = user_data;
   g_autoptr(GError) error = NULL;
   g_autofree gchar *old_governor = NULL;
+  int previous;
 
   g_assert (SYSPROF_IS_HELPERS (helpers));
   g_assert (G_IS_ASYNC_RESULT (result));
@@ -217,7 +267,13 @@ enable_governor_cb (GObject      *object,
 
   g_clear_pointer (&self->old_governor, g_free);
 
-  sysprof_source_emit_finished (SYSPROF_SOURCE (self));
+  /* Restore paranoid setting */
+  previous = self->old_paranoid;
+  sysprof_helpers_set_paranoid_async (helpers,
+                                      previous,
+                                      NULL,
+                                      enable_paranoid_cb,
+                                      g_steal_pointer (&self));
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]