Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6129251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:43:14+00:00 2026-05-23T16:43:14+00:00

On i386 linux. Preferably in c/(c/posix std libs)/proc if possible. If not is there

  • 0

On i386 linux. Preferably in c/(c/posix std libs)/proc if possible. If not is there any piece of assembly or third party library that can do this?

Edit: I’m trying to develop test whether a kernel module clear a cache line or the whole proccesor(with wbinvd()). Program runs as root but I’d prefer to stay in user space if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:43:14+00:00Added an answer on May 23, 2026 at 4:43 pm

    Cache coherent systems do their utmost to hide such things from you. I think you will have to observe it indirectly, either by using performance counting registers to detect cache misses or by carefully measuring the time to read a memory location with a high resolution timer.

    This program works on my x86_64 box to demonstrate the effects of clflush. It times how long it takes to read a global variable using rdtsc. Being a single instruction tied directly to the CPU clock makes direct use of rdtsc ideal for this.

    Here is the output:

    took 81 ticks
    took 81 ticks
    flush: took 387 ticks
    took 72 ticks
    

    You see 3 trials: The first ensures i is in the cache (which it is, because it was just zeroed as part of BSS), the second is a read of i that should be in the cache. Then clflush kicks i out of the cache (along with its neighbors) and shows that re-reading it takes significantly longer. A final read verifies it is back in the cache. The results are very reproducible and the difference is substantial enough to easily see the cache misses. If you cared to calibrate the overhead of rdtsc() you could make the difference even more pronounced.

    If you can’t read the memory address you want to test (although even mmap of /dev/mem should work for these purposes) you may be able to infer what you want if you know the cacheline size and associativity of the cache. Then you can use accessible memory locations to probe the activity in the set you’re interested in.

    Source code:

    (1. Use static inline or other methods referenced here if using newer gcc
    2. Inspired by the comment, better use asm volatile ("lfence;rdtsc;lfence" : "=a" (a), "=d" (d)::"memory"); if your CPU may reorder the instruction at runtime. Here volatile implies no need of mfence around cflush to ensure that
    instructions after cflush can observe its effect)

    #include <stdio.h>
    #include <stdint.h>
    
    inline void
    clflush(volatile void *p)
    {
        asm volatile ("clflush (%0)" :: "r"(p));
    }
    
    inline uint64_t
    rdtsc()
    {
        unsigned long a, d;
        asm volatile ("rdtsc" : "=a" (a), "=d" (d));
        return a | ((uint64_t)d << 32);
    }
    
    volatile int i;
    
    inline void
    test()
    {
        uint64_t start, end;
        volatile int j;
    
        start = rdtsc();
        j = i;
        end = rdtsc();
        printf("took %lu ticks\n", end - start);
    }
    
    int
    main(int ac, char **av)
    {
        test();
        test();
        printf("flush: ");
        clflush(&i);
        test();
        test();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it (easily) possible to use software floating point on i386 linux without incurring
I'm working with GNU assembler on i386, generally under 32-bit Linux (I'm also aiming
I've got an executable file (C++, i386, compiled under MacOS/X Tiger, if it matters)
I am currently porting our code from an alpha (Tru64) to an i386 processor
I am using windows emacs with specifications below. GNU Emacs 23.0.91.1 (i386-mingw-nt5.1.2600) of 2009-02-26
Right now I'm using the following: export CFLAGS=-O2-isysroot/Developer/SDKs/MacOSX10.5.sdk -arch i386 -I/sw/include/ export LDFLAGS=-Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk,-L/sw/lib/ sudo
I have this piece of script : #!/usr/bin/perl use strict; use warnings; use Data::Dumper;
Very strange for me: # uname -a Linux localhost.localdomain 2.6.18-194.3.1.el5 #1 SMP Thu May
I have the following situation: There is a windows folder that has been mounted
Has anyone attempted using perlembed in Mono on Linux? Here is the link: perlembed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.