Project

General

Profile

Bug #1183 » 0001-Fix-timestamp_end-field-should-include-all-events-wi.patch

ust - Mathieu Desnoyers, 04/30/2019 01:32 PM

View differences:

include/lttng/ust-abi.h
46 46
#define LTTNG_UST_COMM_MAGIC			0xC57C57C5
47 47

  
48 48
/* Version for ABI between liblttng-ust, sessiond, consumerd */
49
#define LTTNG_UST_ABI_MAJOR_VERSION		7
50
#define LTTNG_UST_ABI_MINOR_VERSION		2
49
#define LTTNG_UST_ABI_MAJOR_VERSION		8
50
#define LTTNG_UST_ABI_MINOR_VERSION		0
51 51

  
52 52
enum lttng_ust_instrumentation {
53 53
	LTTNG_UST_TRACEPOINT		= 0,
libringbuffer/frontend_types.h
202 202

  
203 203
	DECLARE_SHMP(struct commit_counters_cold, commit_cold);
204 204
					/* Commit count per sub-buffer */
205
	DECLARE_SHMP(uint64_t, ts_end);	/*
206
					 * timestamp_end per sub-buffer.
207
					 * Time is sampled by the
208
					 * switch_*_end() callbacks
209
					 * which are the last space
210
					 * reservation performed in the
211
					 * sub-buffer before it can be
212
					 * fully committed and
213
					 * delivered. This time value is
214
					 * then read by the deliver
215
					 * callback, performed by the
216
					 * last commit before the buffer
217
					 * becomes readable.
218
					 */
205 219
	long active_readers;		/*
206 220
					 * Active readers count
207 221
					 * standard atomic access (shared)
libringbuffer/ring_buffer_frontend.c
194 194
	for (i = 0; i < chan->backend.num_subbuf; i++) {
195 195
		struct commit_counters_hot *cc_hot;
196 196
		struct commit_counters_cold *cc_cold;
197
		uint64_t *ts_end;
197 198

  
198 199
		cc_hot = shmp_index(handle, buf->commit_hot, i);
199 200
		if (!cc_hot)
......
201 202
		cc_cold = shmp_index(handle, buf->commit_cold, i);
202 203
		if (!cc_cold)
203 204
			return;
205
		ts_end = shmp_index(handle, buf->ts_end, i);
206
		if (!ts_end)
207
			return;
204 208
		v_set(config, &cc_hot->cc, 0);
205 209
		v_set(config, &cc_hot->seq, 0);
206 210
		v_set(config, &cc_cold->cc_sb, 0);
211
		*ts_end = 0;
207 212
	}
208 213
	uatomic_set(&buf->consumed, 0);
209 214
	uatomic_set(&buf->record_disabled, 0);
......
368 373
		goto free_commit;
369 374
	}
370 375

  
376
	align_shm(shmobj, __alignof__(uint64_t));
377
	set_shmp(buf->ts_end,
378
		 zalloc_shm(shmobj,
379
			sizeof(uint64_t) * chan->backend.num_subbuf));
380
	if (!shmp(handle, buf->ts_end)) {
381
		ret = -ENOMEM;
382
		goto free_commit_cold;
383
	}
384

  
385

  
371 386
	ret = lib_ring_buffer_backend_create(&buf->backend, &chan->backend,
372 387
			cpu, handle, shmobj);
373 388
	if (ret) {
......
414 429

  
415 430
	/* Error handling */
416 431
free_init:
432
	/* ts_end will be freed by shm teardown */
433
free_commit_cold:
417 434
	/* commit_cold will be freed by shm teardown */
418 435
free_commit:
419 436
	/* commit_hot will be freed by shm teardown */
......
1795 1812
	unsigned long oldidx = subbuf_index(offsets->old - 1, chan);
1796 1813
	unsigned long commit_count, padding_size, data_size;
1797 1814
	struct commit_counters_hot *cc_hot;
1815
	uint64_t *ts_end;
1798 1816

  
1799 1817
	data_size = subbuf_offset(offsets->old - 1, chan) + 1;
1800 1818
	padding_size = chan->backend.subbuf_size - data_size;
1801 1819
	subbuffer_set_data_size(config, &buf->backend, oldidx, data_size,
1802 1820
				handle);
1803 1821

  
1822
	ts_end = shmp_index(handle, buf->ts_end, oldidx);
1823
	if (!ts_end)
1824
		return;
1804 1825
	/*
1805
	 * Order all writes to buffer before the commit count update that will
1806
	 * determine that the subbuffer is full.
1826
	 * This is the last space reservation in that sub-buffer before
1827
	 * it gets delivered. This provides exclusive access to write to
1828
	 * this sub-buffer's ts_end. There are also no concurrent
1829
	 * readers of that ts_end because delivery of that sub-buffer is
1830
	 * postponed until the commit counter is incremented for the
1831
	 * current space reservation.
1832
	 */
1833
	*ts_end = tsc;
1834

  
1835
	/*
1836
	 * Order all writes to buffer and store to ts_end before the commit
1837
	 * count update that will determine that the subbuffer is full.
1807 1838
	 */
1808 1839
	cmm_smp_wmb();
1809 1840
	cc_hot = shmp_index(handle, buf->commit_hot, oldidx);
......
1874 1905
{
1875 1906
	const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
1876 1907
	unsigned long endidx, data_size;
1908
	uint64_t *ts_end;
1877 1909

  
1878 1910
	endidx = subbuf_index(offsets->end - 1, chan);
1879 1911
	data_size = subbuf_offset(offsets->end - 1, chan) + 1;
1880 1912
	subbuffer_set_data_size(config, &buf->backend, endidx, data_size,
1881 1913
				handle);
1914
	ts_end = shmp_index(handle, buf->ts_end, endidx);
1915
	if (!ts_end)
1916
		return;
1917
	/*
1918
	 * This is the last space reservation in that sub-buffer before
1919
	 * it gets delivered. This provides exclusive access to write to
1920
	 * this sub-buffer's ts_end. There are also no concurrent
1921
	 * readers of that ts_end because delivery of that sub-buffer is
1922
	 * postponed until the commit counter is incremented for the
1923
	 * current space reservation.
1924
	 */
1925
	*ts_end = tsc;
1882 1926
}
1883 1927

  
1884 1928
/*
......
2445 2489
	if (caa_likely(v_cmpxchg(config, &cc_cold->cc_sb,
2446 2490
				 old_commit_count, old_commit_count + 1)
2447 2491
		   == old_commit_count)) {
2492
		uint64_t *ts_end;
2493

  
2448 2494
		/*
2449 2495
		 * Start of exclusive subbuffer access. We are
2450 2496
		 * guaranteed to be the last writer in this subbuffer
2451 2497
		 * and any other writer trying to access this subbuffer
2452 2498
		 * in this state is required to drop records.
2499
		 *
2500
		 * We can read the ts_end for the current sub-buffer
2501
		 * which has been saved by the very last space
2502
		 * reservation for the current sub-buffer.
2503
		 *
2504
		 * Order increment of commit counter before reading ts_end.
2453 2505
		 */
2506
		cmm_smp_mb();
2507
		ts_end = shmp_index(handle, buf->ts_end, idx);
2508
		if (!ts_end)
2509
			return;
2454 2510
		deliver_count_events(config, buf, idx, handle);
2455
		config->cb.buffer_end(buf, tsc, idx,
2511
		config->cb.buffer_end(buf, *ts_end, idx,
2456 2512
				      lib_ring_buffer_get_data_size(config,
2457 2513
								buf,
2458 2514
								idx,
2459
- 
(2-2/2)