From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751126AbdJRPiE (ORCPT ); Wed, 18 Oct 2017 11:38:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40705 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750742AbdJRPiD (ORCPT ); Wed, 18 Oct 2017 11:38:03 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BEB527EA9D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jolsa@redhat.com Date: Wed, 18 Oct 2017 17:37:59 +0200 From: Jiri Olsa To: kan.liang@intel.com Cc: acme@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, peterz@infradead.org, jolsa@kernel.org, wangnan0@huawei.com, hekuang@huawei.com, namhyung@kernel.org, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, ak@linux.intel.com Subject: Re: [PATCH V2 4/5] perf record: synthesize event multithreading support Message-ID: <20171018153759.GB512@krava> References: <1508336973-383492-1-git-send-email-kan.liang@intel.com> <1508336973-383492-5-git-send-email-kan.liang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1508336973-383492-5-git-send-email-kan.liang@intel.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 18 Oct 2017 15:38:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 18, 2017 at 07:29:32AM -0700, kan.liang@intel.com wrote: SNIP > +static int record__multithread_synthesize(struct record *rec, > + struct machine *machine, > + struct perf_tool *tool, > + struct record_opts *opts) > +{ > + int i, err, nr_thread = sysconf(_SC_NPROCESSORS_ONLN); > + char name[PATH_MAX]; > + struct stat st; > + > + if (nr_thread <= 1) > + return __machine__synthesize_threads(machine, tool, > + &opts->target, > + rec->evlist->threads, > + process_synthesized_event, > + opts->sample_address, > + opts->proc_map_timeout, > + 1); > + > + rec->synthesized_file = calloc(nr_thread, sizeof(struct perf_data_file)); > + if (rec->synthesized_file == NULL) { > + pr_debug("Could not do multithread synthesize." > + "Roll back to single thread\n"); > + nr_thread = 1; I guess we could fail here anyway.. it'd simplify the code below ;-) jirka > + } else { > + perf_set_multithreaded(); > + for (i = 0; i < nr_thread; i++) { > + snprintf(name, sizeof(name), "%s.%d", > + SYNTHESIZED_PATH, i); > + rec->synthesized_file[i].path = name; > + err = perf_data_file__open(&rec->synthesized_file[i]); > + if (err) { > + pr_err("Failed to open file %s\n", > + rec->synthesized_file[i].path); > + goto free; > + } > + } > + } > + > + err = __machine__synthesize_threads(machine, tool, &opts->target, > + rec->evlist->threads, > + process_synthesized_event, > + opts->sample_address, > + opts->proc_map_timeout, nr_thread); > + if (err < 0) > + goto free; > + > + if (nr_thread > 1) { > + int fd_from, fd_to; > + > + fd_to = rec->session->file->fd; > + for (i = 0; i < nr_thread; i++) { > + fd_from = rec->synthesized_file[i].fd; > + > + fstat(fd_from, &st); > + if (st.st_size == 0) > + continue; > + err = copyfile_offset(fd_from, 0, fd_to, > + lseek(fd_to, 0, SEEK_END), > + st.st_size); > + update_bytes_written(rec, st.st_size); > + } > + } > + > +free: > + if (nr_thread > 1) { > + for (i = 0; i < nr_thread; i++) { > + if (rec->synthesized_file[i].fd > 0) > + perf_data_file__close(&rec->synthesized_file[i]); > + } > + free(rec->synthesized_file); > + perf_set_singlethreaded(); > + } > + > + return err; > +} SNIP