• Jiri Olsa's avatar
    perf daemon: Allow only one daemon over base directory · 8c98be6c
    Jiri Olsa authored
    Add 'lock' file under daemon base and flock it, so only one perf daemon
    can run on top of it.
    
    Each daemon tries to create and lock BASE/lock file, if it's successful
    we are sure we're the only daemon running over the BASE.
    
    Once daemon is finished, file descriptor to lock file is closed and lock
    is released.
    
    Example:
    
      # cat ~/.perfconfig
      [daemon]
      base=/opt/perfdata
    
      [session-cycles]
      run = -m 10M -e cycles --overwrite --switch-output -a
    
      [session-sched]
      run = -m 20M -e sched:* --overwrite --switch-output -a
    
    Starting the daemon:
    
      # perf daemon start
    
    And try once more:
    
      # perf daemon start
      failed: another perf daemon (pid 775594) owns /opt/perfdata
    
    will end up with an error, because there's already one running
    on top of /opt/perfdata.
    
    Committer notes:
    
    Provide lockf(F_TLOCK) when not available, i.e. transform:
    
      lockf(fd, F_TLOCK, 0);
    
    into:
    
      flock(fd, LOCK_EX | LOCK_NB);
    
    Which should be equivalent.
    
    Noticed when cross building to some odd Android NDK.
    Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Alexei Budankov <abudankov@huawei.com>
    Cc: Ian Rogers <irogers@google.com>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Mark Rutland <mark.rutland@arm.com>
    Cc: Michael Petlan <mpetlan@redhat.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Link: https://lore.kernel.org/r/20210208200908.1019149-14-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    8c98be6c
perf-daemon.txt 2.25 KB