* Linux Question
@ 2006-04-10 16:32 Carlos Pardo
2006-04-10 17:56 ` Jeff Garzik
0 siblings, 1 reply; 5+ messages in thread
From: Carlos Pardo @ 2006-04-10 16:32 UTC (permalink / raw)
To: Tejun Heo, Jeff Garzik; +Cc: linux-ide
Linux Gurus,
Does anyone know a way to do 64bit/32bit division in linux kernel space? I'm rewriting a lot of code to use the do_div macro in div64.h but I'm wondering if there's an easier way of doing this. Anyone fought this problem before?
Carlos
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Linux Question
2006-04-10 16:32 Linux Question Carlos Pardo
@ 2006-04-10 17:56 ` Jeff Garzik
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Garzik @ 2006-04-10 17:56 UTC (permalink / raw)
To: Carlos Pardo; +Cc: Tejun Heo, linux-ide
Carlos Pardo wrote:
> Does anyone know a way to do 64bit/32bit division in linux kernel space? I'm rewriting a lot of code to use the do_div macro in div64.h but I'm wondering if there's an easier way of doing this. Anyone fought this problem before?
(please turn on word wrap)
Here's the whole story:
A 64/32 division is normally promoted to 64/64 when generating the asm,
IIRC. With gcc, on a 32-bit platform such as x86, a 64/64 division
causes gcc to emit a function call to do the division, rather than doing
it inline. The 64/64 division operation on 32-bit is so expensive that
it is done in libgcc (a shared library), rather than directly by code
generated from the compiler.
The kernel never links with libgcc (or any other lib, such as libc),
never uses floating point/SSE registers[1], and thus can never contain
code that causes gcc to call libgcc functions.
Often 64/64 can be reduced manually to 64/32, but that requires the use
of do_div() to prevent gcc from generating a call to function that does
not exist in the kernel.
So yes, you'll have to use do_div(), if you cannot accomplish the
division via power-of-2 shifting or similar techniques.
Jeff
[1] well, there are rare cases such as RAID XOR
^ permalink raw reply [flat|nested] 5+ messages in thread
* Linux question
@ 2006-01-11 19:12 mcnernbm
0 siblings, 0 replies; 5+ messages in thread
From: mcnernbm @ 2006-01-11 19:12 UTC (permalink / raw)
To: Andrei Konovalov; +Cc: linuxppc-embedded
[-- Attachment #1: Type: text/html, Size: 1407 bytes --]
[-- Attachment #2: my_adder.cpp --]
[-- Type: application/octet-stream, Size: 4302 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include "my_io.h"
#include "AlgorithmTestTimeStamp/NativeTimeStamp.h"
volatile unsigned long * ioremap(unsigned long physaddr, unsigned size)
{
static int axs_mem_fd = -1;
unsigned long page_addr, ofs_addr, reg, pgmask;
void* reg_mem = NULL;
/*
* looks like mmap wants aligned addresses?
*/
pgmask = getpagesize()-1;
page_addr = physaddr & ~pgmask;
ofs_addr = physaddr & pgmask;
/*
* Don't forget O_SYNC, esp. if address is in RAM region.
* Note: if you do know you'll access in Read Only mode,
* pass O_RDONLY to open, and PROT_READ only to mmap
*/
if (axs_mem_fd == -1) {
axs_mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
if (axs_mem_fd < 0) {
perror("AXS: can't open /dev/mem");
return NULL;
}
}
/* memory map */
reg_mem = mmap(
(caddr_t)reg_mem,
size+ofs_addr,
PROT_READ|PROT_WRITE,
MAP_SHARED,
axs_mem_fd,
page_addr
);
if (reg_mem == MAP_FAILED) {
perror("AXS: mmap error");
close(axs_mem_fd);
return NULL;
}
reg = (unsigned long )reg_mem + ofs_addr;
return (volatile unsigned long *)reg;
}
int iounmap(volatile void *start, size_t length)
{
unsigned long ofs_addr;
ofs_addr = (unsigned long)start & (getpagesize()-1);
/* do some cleanup when you're done with it */
return munmap((long*)start-ofs_addr, length+ofs_addr);
}
int main(void) {
unsigned a;
unsigned b;
unsigned sd_a;
unsigned sd_b;
unsigned a1;
unsigned b1;
unsigned sum;
unsigned sum2;
unsigned flag;
unsigned flag_after;
unsigned long reg0_lower;
unsigned long reg0_upper;
unsigned long reg1_lower;
unsigned long reg1_upper;
unsigned long reg2_lower;
unsigned long reg2_upper;
unsigned long *r0_lower;
unsigned long *r0_upper;
unsigned long *r1_lower;
unsigned long *r1_upper;
unsigned long *r2_lower;
unsigned long *r2_upper;
unsigned long temp_t;
unsigned long a_point;
unsigned long b_point;
unsigned long *a_pointer;
unsigned long *b_pointer;
NativeTimeStamp TS;
printf("input number 1: ");
scanf("%u", &sd_a);
printf("input number 2: ");
scanf("%u", &sd_b);
volatile unsigned long *t = ioremap(0x00000000, 67108864);
if(!t)
exit(1);
temp_t = reinterpret_cast <unsigned long> (t);
a_point = temp_t + 200;
b_point = temp_t + 400;
a_pointer = reinterpret_cast <unsigned long *> (a_point);
b_pointer = reinterpret_cast <unsigned long *> (b_point);
out_le32(a_pointer,sd_a);
printf("Writing Reg 0 Lower\n");
out_le32(b_pointer,sd_b );
printf("Writing Reg 0 Upper\n");
a = in_le32(a_pointer);
printf("A: %u\n" , a);
b = in_le32(b_pointer);
printf("B: %u\n", b);
iounmap(t,67108864);
TS.Init(1,5.0);
TS.RecordTime(1);
\r volatile unsigned long *p = ioremap(0xC9C00000, 256);
if(!p)
exit(1);
reg0_lower = reinterpret_cast <unsigned long> (p);
r0_lower = reinterpret_cast <unsigned long *> (reg0_lower);
reg0_upper = reg0_lower + 4;
r0_upper = reinterpret_cast <unsigned long *> (reg0_upper);
reg1_lower = reg0_lower + 8;
r1_lower = reinterpret_cast <unsigned long *> (reg1_lower);
reg1_upper = reg0_lower + 12;
r1_upper = reinterpret_cast <unsigned long *> (reg1_upper);
reg2_lower = reg0_lower + 16;
r2_lower = reinterpret_cast <unsigned long *> (reg2_lower);
reg2_upper = reg0_lower + 20;
r2_upper = reinterpret_cast <unsigned long *> (reg2_upper);
out_le32(r0_lower,a);
printf("Writing Reg 0 Lower\n");
out_le32(r0_upper,b );
printf("Writing Reg 0 Upper\n");
a1 = in_le32(r0_lower);
printf("Reg1: %u\n" , a1);
b1 = in_le32(r0_upper);
printf("Reg2: %u\n", b1);
out_le32(r2_lower,1);
while (flag != 1)
{flag = in_le32(r2_lower);}
sum = in_le32(r1_lower);
printf("Sum = %u\n", sum);
out_le32(r2_lower,0);
flag_after= in_le32(r1_upper);
printf("Flag After= %u\n", flag_after);
iounmap(p,256);
TS.RecordTime(1);
TS.RecordTime(1);
sum2 = a + b;
printf("Sum Using No Hardware: %u\n", sum2);
TS.RecordTime(1);
printf("End");
TS.OutputLogRecords();
return 0;
}
[-- Attachment #3: my_io.h --]
[-- Type: application/octet-stream, Size: 2385 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
typedef unsigned char my8;
typedef unsigned short my16;
typedef unsigned long my32;
#define readb(addr) in_8((volatile my8 *)(addr))
#define writeb(b,addr) out_8((volatile my8 *)(addr), (b))
#define readw(addr) in_le16((volatile myu16 *)(addr))
#define readl(addr) in_le32((volatile my32 *)(addr))
#define writew(b,addr) out_le16((volatile my16 *)(addr),(b))
#define writel(b,addr) out_le32((volatile my32 *)(addr),(b))
extern inline int in_8(volatile unsigned char *addr)
{
int ret;
__asm__ __volatile__(
"lbz%U1%X1 %0,%1;\n"
"twi 0,%0,0;\n"
"isync" : "=r" (ret) : "m" (*addr));
return ret;
}
extern inline void out_8(volatile unsigned char *addr, int val)
{
__asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
}
extern inline int in_le16(volatile unsigned short *addr)
{
int ret;
__asm__ __volatile__("lhbrx %0,0,%1;\n"
"twi 0,%0,0;\n"
"isync" : "=r" (ret) :
"r" (addr), "m" (*addr));
return ret;
}
extern inline int in_be16(volatile unsigned short *addr)
{
int ret;
__asm__ __volatile__("lhz%U1%X1 %0,%1;\n"
"twi 0,%0,0;\n"
"isync" : "=r" (ret) : "m" (*addr));
return ret;
}
extern inline void out_le16(volatile unsigned short *addr, int val)
{
__asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
"r" (val), "r" (addr));
}
extern inline void out_be16(volatile unsigned short *addr, int val)
{
__asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
}
extern inline unsigned in_le32(volatile unsigned long *addr)
{
unsigned ret;
__asm__ __volatile__("lwbrx %0,0,%1;\n"
"twi 0,%0,0;\n"
"isync" : "=r" (ret) :
"r" (addr), "m" (*addr));
return ret;
}
extern inline unsigned in_be32(volatile unsigned long *addr)
{
unsigned ret;
__asm__ __volatile__("lwz%U1%X1 %0,%1;\n"
"twi 0,%0,0;\n"
"isync" : "=r" (ret) : "m" (*addr));
return ret;
}
extern inline void out_le32(volatile unsigned long *addr, int val)
{
__asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
"r" (val), "r" (addr));
}
extern inline void out_be32(volatile unsigned long *addr, int val)
{
__asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
}
^ permalink raw reply [flat|nested] 5+ messages in thread* Linux Question
@ 2002-12-11 21:47 root
2002-12-11 22:10 ` Richard B. Johnson
0 siblings, 1 reply; 5+ messages in thread
From: root @ 2002-12-11 21:47 UTC (permalink / raw)
To: linux-kernel
How do I see my C: drive in linux? I wanted to play my mp3's but there is
not C: drive.
Also, why can't I use AOL in Linux? I put the CD in but nothing happens.
Thanks,
-- Muffy
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Linux Question
2002-12-11 21:47 Linux Question root
@ 2002-12-11 22:10 ` Richard B. Johnson
0 siblings, 0 replies; 5+ messages in thread
From: Richard B. Johnson @ 2002-12-11 22:10 UTC (permalink / raw)
To: root; +Cc: linux-kernel
On Wed, 11 Dec 2002 root@ajvar.org wrote:
> How do I see my C: drive in linux? I wanted to play my mp3's but there is
> not C: drive.
>
> Also, why can't I use AOL in Linux? I put the CD in but nothing happens.
>
> Thanks,
>
> -- Muffy
>
I pretend that this is not a troll. From the root account, you
look at /etc/fstab and see if your distributor put an entry
into this condiguration file. You do "more /etc/fstab" to see
this file. Look for msdos for the type. If you find such a
type, the second column shows where it is mounted. You can
"cd" to that mount-point to look at the file-system.
If you don't have an entry, you can try:
mount -t mdsos /dev/hda1 /mnt
This might mount a ms-dos file-system on your first drive if
it exists. Drive C: might be NTFS instead of DOS. You can just
execute "mount /dev/hda1 /mnt" and see if that works.
As for AOL, maybe you have a AOL CD that will work under Linux.
You need to mount that CD to review its contents. There should
be a cdrom sim-link already installed so you should be able to
do:
mount /dev/cdrom /mnt
This should make it visible on the /mnt mount-point. I really
doubt if AOL put linux executables on that CD, though. You can
use your favorite web-crawler (Netscape) to connect to AOL and
it will save your configuration after you set everything up. Once
you are on the internet (which you are), you really don't need
that CD/ROM.
Further inquiries should be sent to your distributor's help-desk,
not the linux-kernel list.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-04-10 17:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-04-10 16:32 Linux Question Carlos Pardo
2006-04-10 17:56 ` Jeff Garzik
-- strict thread matches above, loose matches on Subject: below --
2006-01-11 19:12 Linux question mcnernbm
2002-12-11 21:47 Linux Question root
2002-12-11 22:10 ` Richard B. Johnson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.