Skip to contentSkip to conversation

potential /dev/urandom scalability improvement

DISCUSSION Andi Kleen 2 participants 2 messages Mar 27, 2004 7 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Andi Kleen

author
#7 lore raw
Quoted 14 lines · Andrew Morton

I think this gets it right, but I probably screwed something up.

static inline void prefetch_range(void *addr, size_t len) {

#ifdef ARCH_HAS_PREFETCH
	char *cp;
	unsigned long end;

	end = ((unsigned long)addr + len + PREFETCH_STRIDE - 1);
	end &= ~(PREFETCH_STRIDE - 1);

	for (cp = addr; cp < (char *)end; cp += PREFETCH_STRIDE)
		prefetch(cp);
Quoted 2 lines

#endif
}

The memory/bus controller usually only has a limited queue of outstanding transactions and for a big buffer you will likely overflow it. Also usually on modern CPUs it is enough to do prefetch for 2-3 cache lines at the beginning, then an automatic hardware prefetcher will kick in and take care of the rest.

-Andi

#8 lore raw
Quoted 18 lines · Andi Kleen
Quoted 14 lines · Andrew Morton

I think this gets it right, but I probably screwed something up.

static inline void prefetch_range(void *addr, size_t len) {

#ifdef ARCH_HAS_PREFETCH
	char *cp;
	unsigned long end;

	end = ((unsigned long)addr + len + PREFETCH_STRIDE - 1);
	end &= ~(PREFETCH_STRIDE - 1);

	for (cp = addr; cp < (char *)end; cp += PREFETCH_STRIDE)
		prefetch(cp);
Quoted 2 lines

#endif
}

Quoted 5 lines

The memory/bus controller usually only has a limited queue of outstanding transactions and for a big buffer you will likely overflow it. Also usually on modern CPUs it is enough to do prefetch for 2-3 cache lines at the beginning, then an automatic hardware prefetcher will kick in and take care of the rest.

Presumable the automatic prefetcher doesn't deal well with non-sequential access patterns. But I suspect the right thing to do is put the knowledge of what's sensible for prefetch priming inside an arch-specific prefetch_range.

Signature · 1 line
Matt Mackall : http://www.selenic.com : Linux development and consulting