建议使用以下浏览器,以获得最佳体验。 IE 9.0+以上版本 Chrome 31+ 谷歌浏览器 Firefox 30+ 火狐浏览器
请选择 进入手机版 | 继续访问电脑版
设置昵称

在此一键设置昵称,即可参与社区互动!

确定
我再想想
选择版块
标签
您还可以添加5个标签
  • 没有搜索到和“关键字”相关的标签
  • 云产品
  • 解决方案
  • 技术领域
  • 通用技术
  • 平台功能
取消

aarom

发帖: 8粉丝: 4

发消息 + 关注

更新于2021年01月22日 12:01:24 684 4
直达本楼层的链接
楼主
显示全部楼层
[干货分享] [手动迁移纪实]淘宝文件系统tfs迁移之tfs

迁移环境:

操作系统:

    CentOS Linux release 7.6.1810 (AltArch) Linux ### 4.14.0-115.el7a.0.1.aarch64 #1 SMP Sun Nov 25 20:54:21 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux

组件: tfs(开源地址:https://github.com/alibaba/tfs/tree/release-2.2.13)

依赖:jemalloc,mysql-connector-c,zlib-devel,libuuid,libtbsys.so,libtbnet.so(后两个的迁移案例:https://bbs.huaweicloud.com/forum/thread-102614-1-1.html)

迁移过程:里面的脚本等小错误还是比较多的,但这些都不是重点,稍微修改一下就好(后面附带修改后的完整代码),来看看一下报错

    unknown mnemonic 'lock'  -- 'lock'

    unknown mnemonic 'xaddl' -- xaddl x20,[x0]

    unknown mnemonic 'lock'  --  'lock'

    unknown mnemonic 'xaddl'  --  xaddl x7,[x1]

错误类似上一篇https://bbs.huaweicloud.com/forum/thread-102614-1-1.html

我们接着看具体的代码:src/common/atomic.h

-----------------------------------------------------------------------------------------------------

#if defined(__i386__) || defined(__x86_64__)

    

    // Atomic operations that C can't guarantee us.  Useful for

    // resource counting etc..

    // SMP lock prefix                                                                                                           

    #ifdef CONFIG_SMP

    #define LOCK_PREFIX "lock ; "

    #else

    #define LOCK_PREFIX ""

    #endif


    //return: the incremented value;

    /// 原子地做 8位,16位,32位,64位的++i的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数加1以后的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_inc(volatile uint64_t * pv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq $1,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          "incq %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    #endif

    

    static __inline__ uint32_t atomic_inc(volatile uint32_t * pv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl $1,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          "incl %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_inc(volatile uint16_t * pv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw $1,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          "incw %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    

    static __inline__ uint8_t  atomic_inc(volatile uint8_t * pv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb $1,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          "incb %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    //return: the decremented value;

    /// 原子地做 8位,16位,32位,64位的--i的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数减1后的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_dec(volatile uint64_t * pv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq $0xffffffffffffffff,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          "decq %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    #endif

    static __inline__ uint32_t atomic_dec(volatile uint32_t * pv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl $0xffffffff,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          "decl %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    static __inline__ uint16_t atomic_dec(volatile uint16_t * pv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw $0xffff,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          "decw %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_dec(volatile uint8_t * pv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb $0xff,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          "decb %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    //return: the initial value of *pv

    /// 原子地做 8位,16位,32位,64位的加法的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数加法之前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_add(volatile uint64_t * pv, const uint64_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq %2,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_add(volatile uint32_t * pv, const uint32_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl %2,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_add(volatile uint16_t * pv, const uint16_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw %2,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_add(volatile uint8_t * pv, const uint8_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb %2,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    //function: set *pv to nv

    //return: the initial value of *pv

    /// 原子地把nv赋值给pv指向的整数,支持8位,16位,32位,84位操作

    /// @param pv 待赋值的整数(目的操作数)

    /// @param nv 向pv赋的整数

    /// @return pv指向的赋值前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_exchange(volatile uint64_t * pv, const uint64_t nv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgq %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_exchange(volatile uint32_t * pv, const uint32_t nv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgl %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_exchange(volatile uint16_t * pv, const uint16_t nv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgw %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_exchange(volatile uint8_t * pv, const uint8_t nv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgb %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); 

      return __res;

    }

    

    //function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing.

    //return: the initial value of *pv

    /// 比较pv和cv,如果两者相等,则返回pv原有数值并且把nv赋值给pv

    /// 否则什么也不作,返回pv原有数值

    /// @param pv 待赋值的整数(目的操作数)

    /// @param nv 向pv赋的整数

    /// @param cv 和pv比较的整数

    /// @return pv指向的操作前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_compare_exchange(volatile uint64_t * pv, 

        const uint64_t nv, const uint64_t cv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgq %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_compare_exchange(volatile uint32_t * pv, 

        const uint32_t nv, const uint32_t cv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgl %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    static __inline__ uint16_t atomic_compare_exchange(volatile uint16_t * pv, 

        const uint16_t nv, const uint16_t cv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgw %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    static __inline__ uint8_t atomic_compare_exchange(volatile uint8_t * pv, 

        const uint8_t nv, const uint8_t cv)

    {

      register unsigned char  __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgb %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    

    typedef void * pvoid;

    

    //function: set *pv to nv

    //return: the initial value of *pv

    /// 把nv原子地赋值给*pv

    static __inline__ pvoid atomic_exchange_pointer(volatile pvoid * pv, const pvoid nv)

    {

    #ifdef __x86_64__

      return (pvoid) atomic_exchange((uint64_t *) pv, (uint64_t) nv);

    #else

      return (pvoid) atomic_exchange((uint32_t *) pv, (uint32_t) nv);

    #endif

    }

    //function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing.

    //return: the initial value of *pv

    /// 比较cv和*pv,如果两者相等则把nv赋值给*pv,并且返回*pv原有数值

    /// 否则返回*pv原有数值,不做赋值操作

    static __inline__ pvoid atomic_compare_exchange_pointer(volatile pvoid * pv, 

        const pvoid nv, const pvoid cv)

    {

    #ifdef __x86_64__

      return (pvoid) atomic_compare_exchange((uint64_t *) pv, (uint64_t) nv, (uint64_t)cv);

    #else

      return (pvoid) atomic_compare_exchange((uint32_t *) pv, (uint32_t) nv, (uint32_t)cv);

    #endif

    }

    

    #undef LOCK_PREFIX


好嘛,又是定义x86下的asm函数,好吧,继续使用gcc的内建__sync的原子操作函数来做实现,修改后的文件如下:


tfs-release-2.2.13.zip 1.24 MB,下载次数:0

tfs-release-2.2.16.zip 2.87 MB,下载次数:0

举报
分享

分享文章到朋友圈

分享文章到微博

aarom

发帖: 8粉丝: 4

发消息 + 关注

发表于2021年01月21日 15:14:08
直达本楼层的链接
沙发
显示全部楼层

---------------------------------------------------------------------atomic.h--------------------------------------------------------------------

////===================================================================

 //

 //

 // Copyright (C) 2010 Taobao.com, Inc.

 //

 // -------------------------------------------------------------------

 //

 // Description

 //

 //

 // -------------------------------------------------------------------

 // 

 // Change Log

 //

////====================================================================


#ifndef  TFS_COMMON_ATOMIC_H_

#define  TFS_COMMON_ATOMIC_H_


namespace tfs 

{

  namespace common 

  {

    // Proclaim we are using SMP

    #ifndef CONFIG_SMP

    # define CONFIG_SMP

    #endif

    

    #if defined(__i386__) || defined(__x86_64__)

    

    // Atomic operations that C can't guarantee us.  Useful for

    // resource counting etc..

    // SMP lock prefix                                                                                                           

    #ifdef CONFIG_SMP

    #define LOCK_PREFIX "lock ; "

    #else

    #define LOCK_PREFIX ""

    #endif


    //return: the incremented value;

    /// 原子地做 8位,16位,32位,64位的++i的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数加1以后的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_inc(volatile uint64_t * pv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq $1,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          "incq %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    #endif

    

    static __inline__ uint32_t atomic_inc(volatile uint32_t * pv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl $1,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          "incl %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_inc(volatile uint16_t * pv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw $1,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          "incw %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    

    static __inline__ uint8_t  atomic_inc(volatile uint8_t * pv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb $1,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          "incb %0"

          :"=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    //return: the decremented value;

    /// 原子地做 8位,16位,32位,64位的--i的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数减1后的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_dec(volatile uint64_t * pv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq $0xffffffffffffffff,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          "decq %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    #endif

    static __inline__ uint32_t atomic_dec(volatile uint32_t * pv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl $0xffffffff,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          "decl %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    

    }

    static __inline__ uint16_t atomic_dec(volatile uint16_t * pv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw $0xffff,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          "decw %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_dec(volatile uint8_t * pv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb $0xff,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          "decb %0"

          : "=a" (__res), "=q" (pv): "1" (pv));

      return __res;

    }

    

    //return: the initial value of *pv

    /// 原子地做 8位,16位,32位,64位的加法的操作

    /// 该操作虽然参数和返回值都是无符号型整数,但是一样可以

    /// 对有符号型整数做操作,只需要做适当的参数转换即可

    /// @param pv 指向操作数的指针

    /// @return 操作数加法之前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_add(volatile uint64_t * pv, const uint64_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned long __res;

      __asm__ __volatile__ (

          "movq %2,%0;"

          LOCK_PREFIX "xaddq %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_add(volatile uint32_t * pv, const uint32_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned int __res;

      __asm__ __volatile__ (

          "movl %2,%0;"

          LOCK_PREFIX "xaddl %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_add(volatile uint16_t * pv, const uint16_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned short __res;

      __asm__ __volatile__ (

          "movw %2,%0;"

          LOCK_PREFIX "xaddw %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_add(volatile uint8_t * pv, const uint8_t av)

    {

      //:"=a" (__res), "=q" (pv): "m"(av), "1" (pv));

      register unsigned char __res;

      __asm__ __volatile__ (

          "movb %2,%0;"

          LOCK_PREFIX "xaddb %0,(%1);"

          :"=a" (__res), "=q" (pv): "mr"(av), "1" (pv));

      return __res;

    }

    

    //function: set *pv to nv

    //return: the initial value of *pv

    /// 原子地把nv赋值给pv指向的整数,支持8位,16位,32位,84位操作

    /// @param pv 待赋值的整数(目的操作数)

    /// @param nv 向pv赋的整数

    /// @return pv指向的赋值前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_exchange(volatile uint64_t * pv, const uint64_t nv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgq %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_exchange(volatile uint32_t * pv, const uint32_t nv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgl %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    

    static __inline__ uint16_t atomic_exchange(volatile uint16_t * pv, const uint16_t nv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgw %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv));

      return __res;

    }

    

    static __inline__ uint8_t  atomic_exchange(volatile uint8_t * pv, const uint8_t nv)

    {

      register unsigned char __res;

      __asm__ __volatile__ (

          "1:"

          LOCK_PREFIX "cmpxchgb %3,(%1);"                \

          "jne 1b": 

          "=a" (__res), "=q" (pv): "1" (pv), "q" (nv), "0" (*pv)); 

      return __res;

    }

    

    //function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing.

    //return: the initial value of *pv

    /// 比较pv和cv,如果两者相等,则返回pv原有数值并且把nv赋值给pv

    /// 否则什么也不作,返回pv原有数值

    /// @param pv 待赋值的整数(目的操作数)

    /// @param nv 向pv赋的整数

    /// @param cv 和pv比较的整数

    /// @return pv指向的操作前的数值

    #ifdef __x86_64__

    static __inline__ uint64_t atomic_compare_exchange(volatile uint64_t * pv, 

        const uint64_t nv, const uint64_t cv)

    {

      register unsigned long __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgq %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    #endif

    static __inline__ uint32_t atomic_compare_exchange(volatile uint32_t * pv, 

        const uint32_t nv, const uint32_t cv)

    {

      register unsigned int __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgl %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    static __inline__ uint16_t atomic_compare_exchange(volatile uint16_t * pv, 

        const uint16_t nv, const uint16_t cv)

    {

      register unsigned short __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgw %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    static __inline__ uint8_t atomic_compare_exchange(volatile uint8_t * pv, 

        const uint8_t nv, const uint8_t cv)

    {

      register unsigned char  __res;

      __asm__ __volatile__ (

          LOCK_PREFIX "cmpxchgb %3,(%1)"

          : "=a" (__res), "=q" (pv) : "1" (pv), "q" (nv), "0" (cv));

      return __res;

    }

    

    typedef void * pvoid;

    

    //function: set *pv to nv

    //return: the initial value of *pv

    /// 把nv原子地赋值给*pv

    static __inline__ pvoid atomic_exchange_pointer(volatile pvoid * pv, const pvoid nv)

    {

    #ifdef __x86_64__

      return (pvoid) atomic_exchange((uint64_t *) pv, (uint64_t) nv);

    #else

      return (pvoid) atomic_exchange((uint32_t *) pv, (uint32_t) nv);

    #endif

    }

    //function: compare *pv to cv, if equal, set *pv to nv, otherwise do nothing.

    //return: the initial value of *pv

    /// 比较cv和*pv,如果两者相等则把nv赋值给*pv,并且返回*pv原有数值

    /// 否则返回*pv原有数值,不做赋值操作

    static __inline__ pvoid atomic_compare_exchange_pointer(volatile pvoid * pv, 

        const pvoid nv, const pvoid cv)

    {

    #ifdef __x86_64__

      return (pvoid) atomic_compare_exchange((uint64_t *) pv, (uint64_t) nv, (uint64_t)cv);

    #else

      return (pvoid) atomic_compare_exchange((uint32_t *) pv, (uint32_t) nv, (uint32_t)cv);

    #endif

    }

    

    #undef LOCK_PREFIX

    

#elif defined(__aarch64__)

    #define atomic_inc_bytype(ptr,type) \

    ({ \

  typeof(type) c = __sync_add_and_((ptr),1); \

  c ; \

})

   

#define atomic_dec_bytype(ptr,type) \

({ \

 typeof(type) c = __sync_sub_and_((ptr),1); \

 c ; \

})

   #define atomic_add_bytype(ptr,v,type) \

({ \

 typeof(type) c = __sync__and_add((ptr),v); \

 c ; \

   })

 

#define atomic_exchange(ptr,v,type) \

({ \

 typeof(type) c = __sync_lock_test_and_set((ptr),v); \

 c ; \

})

   

#define atomic_compare_exchange(ptr,newv,oldv,type) \

({ \

 typeof(type) c = __sync_val_compare_and_swap((ptr),oldv,newv); \

 c ; \

    })

    #else // #if defined(__i386__) || defined(__x86_64__)

    

    #error "must compiled on i386 or x86_64"

    

    #endif //

  }

}


#endif // TFS_COMMON_ATOMIC_H_ 

-----------------------------------------------------------------------------------------------------------------------------

迁移结果如下:

image.png

image.png

image.png

image.png

到此,整个淘宝的文件系统tfs已经迁移完毕



点赞1 评论 引用 举报

Jack20

发帖: 117粉丝: 155

发消息 + 关注

发表于2021年01月21日 17:58:06
直达本楼层的链接
板凳
显示全部楼层

满满的干货,感谢分享

点赞 评论 引用 举报

HW小龙

发帖: 7粉丝: 5

发消息 + 关注

发表于2021年01月22日 19:03:18
直达本楼层的链接
地板
显示全部楼层

虽然我看不懂,但是感觉好厉害的样子。

点赞 评论 引用 举报

重新来过

发帖: 211粉丝: 12

发消息 + 关注

发表于2021年01月24日 09:35:52
直达本楼层的链接
5#
显示全部楼层

感谢分享

点赞 评论 引用 举报

游客

富文本
Markdown
您需要登录后才可以回帖 登录 | 立即注册