MINOR: activity: make profiling more manageable

In 2.0, commit d2d3348ac ("MINOR: activity: enable automatic profiling
turn on/off") introduced an automatic mode to enable/disable profiling.
The problem is that the automatic mode automatically changes to on/off,
which implied that the forced on/off modes aren't sticky anymore. It's
annoying when debugging because as soon as the load decreases, profiling
stops.

This makes a small change which ought to have been done first, which
consists in having two states for "auto" (auto-on, auto-off) to
distinguish them from the forced states. Setting to "auto" in the config
defaults to "auto-off" as before, and setting it on the CLI switches to
auto but keeps the current operating state.

This is simple enough to be backported to older releases if needed.
diff --git a/src/activity.c b/src/activity.c
index 53721ef..79aad3e 100644
--- a/src/activity.c
+++ b/src/activity.c
@@ -21,7 +21,7 @@
 
 
 /* bit field of profiling options. Beware, may be modified at runtime! */
-unsigned int profiling = HA_PROF_TASKS_AUTO;
+unsigned int profiling = HA_PROF_TASKS_AOFF;
 unsigned long task_profiling_mask = 0;
 
 /* One struct per thread containing all collected measurements */
@@ -49,7 +49,7 @@
 	if (strcmp(args[1], "on") == 0)
 		profiling = (profiling & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_ON;
 	else if (strcmp(args[1], "auto") == 0)
-		profiling = (profiling & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_AUTO;
+		profiling = (profiling & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_AOFF;
 	else if (strcmp(args[1], "off") == 0)
 		profiling = (profiling & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_OFF;
 	else {
@@ -75,8 +75,14 @@
 	}
 	else if (strcmp(args[3], "auto") == 0) {
 		unsigned int old = profiling;
-		while (!_HA_ATOMIC_CAS(&profiling, &old, (old & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_AUTO))
-			;
+		unsigned int new;
+
+		do {
+			if ((old & HA_PROF_TASKS_MASK) >= HA_PROF_TASKS_AON)
+				new = (old & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_AON;
+			else
+				new = (old & ~HA_PROF_TASKS_MASK) | HA_PROF_TASKS_AOFF;
+		} while (!_HA_ATOMIC_CAS(&profiling, &old, new));
 	}
 	else if (strcmp(args[3], "off") == 0) {
 		unsigned int old = profiling;
@@ -103,7 +109,8 @@
 	chunk_reset(&trash);
 
 	switch (profiling & HA_PROF_TASKS_MASK) {
-	case HA_PROF_TASKS_AUTO: str="auto"; break;
+	case HA_PROF_TASKS_AOFF: str="auto-off"; break;
+	case HA_PROF_TASKS_AON:  str="auto-on"; break;
 	case HA_PROF_TASKS_ON:   str="on"; break;
 	default:                 str="off"; break;
 	}