tools/testing/selftests/net/tcp_mmap.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/tcp_mmap.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/tcp_mmap.c
Extension
.c
Size
15934 bytes
Lines
613
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (raddr == (void *)-1) {
			perror("mmap");
			zflg = 0;
		} else {
			addr = ALIGN_PTR_UP(raddr, map_align);
		}
	}
	if (integrity) {
		ctx = EVP_MD_CTX_new();
		if (!ctx) {
			perror("cannot enable SHA computing");
			goto error;
		}
		EVP_DigestInit_ex(ctx, EVP_sha256(), NULL);
	}
	while (1) {
		struct pollfd pfd = { .fd = fd, .events = POLLIN, };
		int sub;

		poll(&pfd, 1, 10000);
		if (zflg) {
			socklen_t zc_len = sizeof(zc);
			int res;

			memset(&zc, 0, sizeof(zc));
			zc.address = (__u64)((unsigned long)addr);
			zc.length = min(chunk_size, FILE_SZ - total);

			res = getsockopt(fd, IPPROTO_TCP, TCP_ZEROCOPY_RECEIVE,
					 &zc, &zc_len);
			if (res == -1)
				break;

			if (zc.length) {
				assert(zc.length <= chunk_size);
				if (integrity)
					EVP_DigestUpdate(ctx, addr, zc.length);
				total_mmap += zc.length;
				if (xflg)
					hash_zone(addr, zc.length);
				/* It is more efficient to unmap the pages right now,
				 * instead of doing this in next TCP_ZEROCOPY_RECEIVE.
				 */
				madvise(addr, zc.length, MADV_DONTNEED);
				total += zc.length;
			}
			if (zc.recv_skip_hint) {
				assert(zc.recv_skip_hint <= chunk_size);
				lu = read(fd, buffer, min(zc.recv_skip_hint,
							  FILE_SZ - total));
				if (lu > 0) {
					if (integrity)
						EVP_DigestUpdate(ctx, buffer, lu);
					if (xflg)
						hash_zone(buffer, lu);
					total += lu;
				}
				if (lu == 0)
					goto end;
			}
			continue;
		}
		sub = 0;
		while (sub < chunk_size) {
			lu = read(fd, buffer + sub, min(chunk_size - sub,
							FILE_SZ - total));
			if (lu == 0)
				goto end;
			if (lu < 0)
				break;
			if (integrity)
				EVP_DigestUpdate(ctx, buffer + sub, lu);
			if (xflg)
				hash_zone(buffer + sub, lu);
			total += lu;
			sub += lu;
		}
	}
end:
	gettimeofday(&t1, NULL);
	delta_usec = (t1.tv_sec - t0.tv_sec) * 1000000 + t1.tv_usec - t0.tv_usec;

	if (integrity) {
		fcntl(fd, F_SETFL, 0);
		EVP_DigestFinal_ex(ctx, digest, &digest_len);
		lu = read(fd, buffer, SHA256_DIGEST_LENGTH);
		if (lu != SHA256_DIGEST_LENGTH)
			perror("Error: Cannot read SHA256\n");

		if (memcmp(digest, buffer,

Annotation

Implementation Notes