memcpy performance issue

Open
#3,480 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
c
Domain
performance

Research direction

Start with the provided a.c program and run it using make && ./a to verify the reported timing on the Raspberry Pi 4 environment. Then identify whether the measured behavior maps to this repository and determine the relevant entry point; done requires a confirmed cause and a documented or implemented resolution.

Written by the indexing model from the issue text.

Description

Describe the bug
memcpy take a long time (see example program)
can i do something to speed this up? alignment?

To reproduce
make a && ./a

Expected behaviour
hopfully be faster

Actual behaviour
takes up to 30ms on a rpi4

System
Copy and paste the results of the raspinfo command in to this section. Alternatively, copy and paste a pastebin link, or add answers to the following questions:

  • Which model of Raspberry Pi?
    rpi4
  • Which OS and version (cat /etc/rpi-issue)?
    Raspberry Pi reference 2020-02-14
    Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, e577677b623b577f2a0ec7cfaffc3c27da005da3, stage2
  • Which firmware version (vcgencmd version)?
  • Which kernel version (uname -a)?

Additional context

#include <time.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>

static void __utimer_start(struct timeval *tm1)
{
    gettimeofday(tm1, NULL);
}

static unsigned long long __utimer_stop(struct timeval *tm1)
{
    struct timeval tm2;
    gettimeofday(&tm2, NULL);
    unsigned long long t = 1000 * (tm2.tv_sec - tm1->tv_sec) + (tm2.tv_usec - tm1->tv_usec) / 1000;

    printf("%llu ms\n", t);
    return t;
}

int main()
{
    int size1 = 30000000;
    int size2 = 8*1024*1024;

    char *buf = calloc(1, size1);
    char *buf2 = calloc(1, size2);

    struct timeval tm_01_007;
    __utimer_start(&tm_01_007);

    memcpy(buf, buf2, size2);
    memcpy(buf, buf2, size2);
    memcpy(buf, buf2, size2);

    long long timspan_in_ms;
    timspan_in_ms = __utimer_stop(&tm_01_007);

    free(buf);
    free(buf2);

    return 0;
}

save as a.c

Dominant language
C
Stars
13.2k
Forks
5.5k
Avg merge
2d 21h
Merged PRs (30d)
21

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raspberrypi/linux

All issues in raspberrypi/linux

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.