On Wed, Jul 06, 2016 at 08:03:28PM +0800, Wangnan (F) wrote:
hum, can't see that.. it's state machine to govern overwrite evlist, right?
On 2016/7/6 19:38, Jiri Olsa wrote:
On Mon, Jul 04, 2016 at 06:20:06AM +0000, Wang Nan wrote:I think even evlist is NULL the state changing is still required.
SNIP
+static voidI'd expect this check at the begining
+record__toggle_overwrite_evsels(struct record *rec,
+ enum overwrite_evt_state state)
+{
+ struct perf_evlist *evlist = rec->overwrite_evlist;
+ enum overwrite_evt_state old_state = rec->overwrite_evt_state;
+ enum action {
+ NONE,
+ PAUSE,
+ RESUME,
+ } action = NONE;
+
+ switch (old_state) {
+ case OVERWRITE_EVT_RUNNING: {
+ switch (state) {
+ case OVERWRITE_EVT_DATA_PENDING:
+ action = PAUSE;
+ break;
+ case OVERWRITE_EVT_RUNNING:
+ case OVERWRITE_EVT_EMPTY:
+ default:
+ goto state_err;
+ }
+ break;
+ }
+ case OVERWRITE_EVT_DATA_PENDING: {
+ switch (state) {
+ case OVERWRITE_EVT_EMPTY:
+ break;
+ case OVERWRITE_EVT_RUNNING:
+ case OVERWRITE_EVT_DATA_PENDING:
+ default:
+ goto state_err;
+ }
+ break;
+ }
+ case OVERWRITE_EVT_EMPTY: {
+ switch (state) {
+ case OVERWRITE_EVT_RUNNING:
+ action = RESUME;
+ break;
+ case OVERWRITE_EVT_EMPTY:
+ case OVERWRITE_EVT_DATA_PENDING:
+ default:
+ goto state_err;
+ }
+ break;
+ }
+ default:
+ WARN_ONCE(1, "Shouldn't get there\n");
+ }
+
+ rec->overwrite_evt_state = state;
+
+ if (!evlist)
+ return;
Actually, the state machine is independent with aux evlist. Even
we without overwritable evsels the state machine is still valid.
So let the state machine runs unconditionally.
if there's no overwrite evlist we should keep the current processing
@@ -1006,8 +1122,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
}
if (trigger_is_hit(&switch_output_trigger)) {
+ /*
+ * If switch_output_trigger is hit, the data in
+ * overwritable ring buffer should have been collected,
+ * so overwrite_evt_state should be set to
+ * OVERWRITE_EVT_EMPTY.
+ *
+ * If SIGUSR2 raise after or during record__mmap_read_all(),
+ * record__mmap_read_all() didn't collect data from
+ * overwritable ring buffer. Read again.
+ */
+ if (rec->overwrite_evt_state == OVERWRITE_EVT_RUNNING)
+ continue;
trigger_ready(&switch_output_trigger);
+ /*
+ * Reenable events in overwrite ring buffer after
+ * record__mmap_read_all(): we should have collected
+ * data from it.
+ */
+ record__toggle_overwrite_evsels(rec, OVERWRITE_EVT_RUNNING);
+
if (!quiet)
fprintf(stderr, "[ perf record: dump data: Woken up %ld times ]\n",
waking);
if it's meant to govern the mmap reading in general
we should at least rename it
jirka